You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
* fix #1906 - implement BITFIELD_RO * set bitfield_ro min version to 6.2
This commit is contained in:
@@ -10,14 +10,14 @@ describe('BITFIELD', () => {
|
||||
behavior: 'WRAP'
|
||||
}, {
|
||||
operation: 'GET',
|
||||
type: 'i8',
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}, {
|
||||
operation: 'OVERFLOW',
|
||||
behavior: 'SAT'
|
||||
}, {
|
||||
operation: 'SET',
|
||||
type: 'i16',
|
||||
encoding: 'i16',
|
||||
offset: 1,
|
||||
value: 0
|
||||
}, {
|
||||
@@ -25,7 +25,7 @@ describe('BITFIELD', () => {
|
||||
behavior: 'FAIL'
|
||||
}, {
|
||||
operation: 'INCRBY',
|
||||
type: 'i32',
|
||||
encoding: 'i32',
|
||||
offset: 2,
|
||||
increment: 1
|
||||
}]),
|
||||
@@ -35,8 +35,12 @@ describe('BITFIELD', () => {
|
||||
|
||||
testUtils.testWithClient('client.bitField', async client => {
|
||||
assert.deepEqual(
|
||||
await client.bitField('key', []),
|
||||
[]
|
||||
await client.bitField('key', [{
|
||||
operation: 'GET',
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
[0]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,26 +1,24 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
export type BitFieldEncoding = `${'i' | 'u'}${number}`;
|
||||
|
||||
type BitFieldType = string; // TODO 'i[1-64]' | 'u[1-63]'
|
||||
|
||||
interface BitFieldOperation<S extends string> {
|
||||
export interface BitFieldOperation<S extends string> {
|
||||
operation: S;
|
||||
}
|
||||
|
||||
interface BitFieldGetOperation extends BitFieldOperation<'GET'> {
|
||||
type: BitFieldType;
|
||||
export interface BitFieldGetOperation extends BitFieldOperation<'GET'> {
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
}
|
||||
|
||||
interface BitFieldSetOperation extends BitFieldOperation<'SET'> {
|
||||
type: BitFieldType;
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
interface BitFieldIncrByOperation extends BitFieldOperation<'INCRBY'> {
|
||||
type: BitFieldType;
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
increment: number;
|
||||
}
|
||||
@@ -44,7 +42,7 @@ export function transformArguments(key: string, operations: BitFieldOperations):
|
||||
case 'GET':
|
||||
args.push(
|
||||
'GET',
|
||||
options.type,
|
||||
options.encoding,
|
||||
options.offset.toString()
|
||||
);
|
||||
break;
|
||||
@@ -52,7 +50,7 @@ export function transformArguments(key: string, operations: BitFieldOperations):
|
||||
case 'SET':
|
||||
args.push(
|
||||
'SET',
|
||||
options.type,
|
||||
options.encoding,
|
||||
options.offset.toString(),
|
||||
options.value.toString()
|
||||
);
|
||||
@@ -61,7 +59,7 @@ export function transformArguments(key: string, operations: BitFieldOperations):
|
||||
case 'INCRBY':
|
||||
args.push(
|
||||
'INCRBY',
|
||||
options.type,
|
||||
options.encoding,
|
||||
options.offset.toString(),
|
||||
options.increment.toString()
|
||||
);
|
||||
|
27
packages/client/lib/commands/BITFIELD_RO.spec.ts
Normal file
27
packages/client/lib/commands/BITFIELD_RO.spec.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './BITFIELD_RO';
|
||||
|
||||
describe('BITFIELD RO', () => {
|
||||
testUtils.isVersionGreaterThanHook([6, 2]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', [{
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
['BITFIELD_RO', 'key', 'GET', 'i8', '0']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.bitFieldRo', async client => {
|
||||
assert.deepEqual(
|
||||
await client.bitFieldRo('key', [{
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
[0]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
26
packages/client/lib/commands/BITFIELD_RO.ts
Normal file
26
packages/client/lib/commands/BITFIELD_RO.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { BitFieldGetOperation } from './BITFIELD';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
type BitFieldRoOperations = Array<
|
||||
Omit<BitFieldGetOperation, 'operation'> &
|
||||
Partial<Pick<BitFieldGetOperation, 'operation'>>
|
||||
>;
|
||||
|
||||
export function transformArguments(key: string, operations: BitFieldRoOperations): Array<string> {
|
||||
const args = ['BITFIELD_RO', key];
|
||||
|
||||
for (const operation of operations) {
|
||||
args.push(
|
||||
'GET',
|
||||
operation.encoding,
|
||||
operation.offset.toString()
|
||||
);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<number | null>;
|
Reference in New Issue
Block a user