You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Support BIT|BYTE option (#2035)
* Support BIT|BYTE option * clean code * clean code * clean code Co-authored-by: leibale <leibale1998@gmail.com>
This commit is contained in:
@@ -11,7 +11,8 @@ describe('BITCOUNT', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('with range', () => {
|
||||
describe('with range', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
start: 0,
|
||||
@@ -20,6 +21,18 @@ describe('BITCOUNT', () => {
|
||||
['BITCOUNT', 'key', '0', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with mode', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
start: 0,
|
||||
end: 1,
|
||||
mode: 'BIT'
|
||||
}),
|
||||
['BITCOUNT', 'key', '0', '1', 'BIT']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.bitCount', async client => {
|
||||
|
@@ -7,6 +7,7 @@ export const IS_READ_ONLY = true;
|
||||
interface BitCountRange {
|
||||
start: number;
|
||||
end: number;
|
||||
mode?: 'BYTE' | 'BIT';
|
||||
}
|
||||
|
||||
export function transformArguments(
|
||||
@@ -20,6 +21,10 @@ export function transformArguments(
|
||||
range.start.toString(),
|
||||
range.end.toString()
|
||||
);
|
||||
|
||||
if (range?.mode) {
|
||||
args.push(range.mode);
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
|
@@ -18,12 +18,19 @@ describe('BITPOS', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('with start, end', () => {
|
||||
it('with start and end', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 1, 1, -1),
|
||||
['BITPOS', 'key', '1', '1', '-1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with start, end and mode', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 1, 1, -1, 'BIT'),
|
||||
['BITPOS', 'key', '1', '1', '-1', 'BIT']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.bitPos', async client => {
|
||||
|
@@ -9,7 +9,8 @@ export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
bit: BitValue,
|
||||
start?: number,
|
||||
end?: number
|
||||
end?: number,
|
||||
mode?: 'BYTE' | 'BIT'
|
||||
): RedisCommandArguments {
|
||||
const args = ['BITPOS', key, bit.toString()];
|
||||
|
||||
@@ -21,6 +22,10 @@ export function transformArguments(
|
||||
args.push(end.toString());
|
||||
}
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user