You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
new "transform arguments" API for better key and metadata extraction (#2733)
* Parser support with all commands * remove "dist" from all imports for consistency * address most of my review comments * small tweak to multi type mapping handling * tweak multi commands / fix addScript cases * nits * addressed all in person review comments * revert addCommand/addScript changes to multi-commands addCommand needs to be there for sendCommand like ability within a multi. If its there, it might as well be used by createCommand() et al, to avoid repeating code. addScript is there (even though only used once), but now made private to keep the logic for bookkeeping near each other.
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ARRAPPEND from './ARRAPPEND';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.ARRAPPEND', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single element', () => {
|
||||
assert.deepEqual(
|
||||
ARRAPPEND.transformArguments('key', '$', 'value'),
|
||||
parseArgs(ARRAPPEND, 'key', '$', 'value'),
|
||||
['JSON.ARRAPPEND', 'key', '$', '"value"']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple elements', () => {
|
||||
assert.deepEqual(
|
||||
ARRAPPEND.transformArguments('key', '$', 1, 2),
|
||||
parseArgs(ARRAPPEND, 'key', '$', 1, 2),
|
||||
['JSON.ARRAPPEND', 'key', '$', '1', '2']
|
||||
);
|
||||
});
|
||||
|
@@ -1,27 +1,23 @@
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
path: RedisArgument,
|
||||
json: RedisJSON,
|
||||
...jsons: Array<RedisJSON>
|
||||
) {
|
||||
const args = new Array<RedisArgument>(4 + jsons.length);
|
||||
args[0] = 'JSON.ARRAPPEND';
|
||||
args[1] = key;
|
||||
args[2] = path;
|
||||
args[3] = transformRedisJsonArgument(json);
|
||||
parser.push('JSON.ARRAPPEND');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, transformRedisJsonArgument(json));
|
||||
|
||||
let argsIndex = 4;
|
||||
for (let i = 0; i < jsons.length; i++) {
|
||||
args[argsIndex++] = transformRedisJsonArgument(jsons[i]);
|
||||
parser.push(transformRedisJsonArgument(jsons[i]));
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,12 +1,13 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ARRINDEX from './ARRINDEX';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.ARRINDEX', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'value'),
|
||||
parseArgs(ARRINDEX, 'key', '$', 'value'),
|
||||
['JSON.ARRINDEX', 'key', '$', '"value"']
|
||||
);
|
||||
});
|
||||
@@ -14,7 +15,7 @@ describe('JSON.ARRINDEX', () => {
|
||||
describe('with range', () => {
|
||||
it('start only', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'value', {
|
||||
parseArgs(ARRINDEX, 'key', '$', 'value', {
|
||||
range: {
|
||||
start: 0
|
||||
}
|
||||
@@ -25,7 +26,7 @@ describe('JSON.ARRINDEX', () => {
|
||||
|
||||
it('with start and stop', () => {
|
||||
assert.deepEqual(
|
||||
ARRINDEX.transformArguments('key', '$', 'value', {
|
||||
parseArgs(ARRINDEX, 'key', '$', 'value', {
|
||||
range: {
|
||||
start: 0,
|
||||
stop: 1
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export interface JsonArrIndexOptions {
|
||||
@@ -9,25 +10,25 @@ export interface JsonArrIndexOptions {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
path: RedisArgument,
|
||||
json: RedisJSON,
|
||||
options?: JsonArrIndexOptions
|
||||
) {
|
||||
const args = ['JSON.ARRINDEX', key, path, transformRedisJsonArgument(json)];
|
||||
parser.push('JSON.ARRINDEX');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, transformRedisJsonArgument(json));
|
||||
|
||||
if (options?.range) {
|
||||
args.push(options.range.start.toString());
|
||||
parser.push(options.range.start.toString());
|
||||
|
||||
if (options.range.stop !== undefined) {
|
||||
args.push(options.range.stop.toString());
|
||||
parser.push(options.range.stop.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ARRINSERT from './ARRINSERT';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.ARRINSERT', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single element', () => {
|
||||
assert.deepEqual(
|
||||
ARRINSERT.transformArguments('key', '$', 0, 'value'),
|
||||
parseArgs(ARRINSERT, 'key', '$', 0, 'value'),
|
||||
['JSON.ARRINSERT', 'key', '$', '0', '"value"']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple elements', () => {
|
||||
assert.deepEqual(
|
||||
ARRINSERT.transformArguments('key', '$', 0, '1', '2'),
|
||||
parseArgs(ARRINSERT, 'key', '$', 0, '1', '2'),
|
||||
['JSON.ARRINSERT', 'key', '$', '0', '"1"', '"2"']
|
||||
);
|
||||
});
|
||||
|
@@ -1,29 +1,24 @@
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
path: RedisArgument,
|
||||
index: number,
|
||||
json: RedisJSON,
|
||||
...jsons: Array<RedisJSON>
|
||||
) {
|
||||
const args = new Array<RedisArgument>(4 + jsons.length);
|
||||
args[0] = 'JSON.ARRINSERT';
|
||||
args[1] = key;
|
||||
args[2] = path;
|
||||
args[3] = index.toString();
|
||||
args[4] = transformRedisJsonArgument(json);
|
||||
parser.push('JSON.ARRINSERT');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, index.toString(), transformRedisJsonArgument(json));
|
||||
|
||||
let argsIndex = 5;
|
||||
for (let i = 0; i < jsons.length; i++) {
|
||||
args[argsIndex++] = transformRedisJsonArgument(jsons[i]);
|
||||
parser.push(transformRedisJsonArgument(jsons[i]));
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ARRLEN from './ARRLEN';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.ARRLEN', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ARRLEN.transformArguments('key'),
|
||||
parseArgs(ARRLEN, 'key'),
|
||||
['JSON.ARRLEN', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
ARRLEN.transformArguments('key', {
|
||||
parseArgs(ARRLEN, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.ARRLEN', 'key', '$']
|
||||
|
@@ -1,20 +1,18 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonArrLenOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, options?: JsonArrLenOptions) {
|
||||
const args = ['JSON.ARRLEN', key];
|
||||
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonArrLenOptions) {
|
||||
parser.push('JSON.ARRLEN');
|
||||
parser.pushKey(key);
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ARRPOP from './ARRPOP';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.ARRPOP', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ARRPOP.transformArguments('key'),
|
||||
parseArgs(ARRPOP, 'key'),
|
||||
['JSON.ARRPOP', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
ARRPOP.transformArguments('key', {
|
||||
parseArgs(ARRPOP, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.ARRPOP', 'key', '$']
|
||||
@@ -22,7 +23,7 @@ describe('JSON.ARRPOP', () => {
|
||||
|
||||
it('with path and index', () => {
|
||||
assert.deepEqual(
|
||||
ARRPOP.transformArguments('key', {
|
||||
parseArgs(ARRPOP, 'key', {
|
||||
path: '$',
|
||||
index: 0
|
||||
}),
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { RedisArgument, ArrayReply, NullReply, BlobStringReply, Command, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { isArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, NullReply, BlobStringReply, Command, UnwrapReply } from '@redis/client/lib/RESP/types';
|
||||
import { isArrayReply } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { transformRedisJsonNullReply } from '.';
|
||||
|
||||
export interface RedisArrPopOptions {
|
||||
@@ -8,20 +9,18 @@ export interface RedisArrPopOptions {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: RedisArrPopOptions) {
|
||||
const args = ['JSON.ARRPOP', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: RedisArrPopOptions) {
|
||||
parser.push('JSON.ARRPOP');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
|
||||
if (options.index !== undefined) {
|
||||
args.push(options.index.toString());
|
||||
parser.push(options.index.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply(reply: NullReply | BlobStringReply | ArrayReply<NullReply | BlobStringReply>) {
|
||||
return isArrayReply(reply) ?
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ARRTRIM from './ARRTRIM';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.ARRTRIM', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ARRTRIM.transformArguments('key', '$', 0, 1),
|
||||
parseArgs(ARRTRIM, 'key', '$', 0, 1),
|
||||
['JSON.ARRTRIM', 'key', '$', '0', '1']
|
||||
);
|
||||
});
|
||||
|
@@ -1,10 +1,12 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, start: number, stop: number) {
|
||||
return ['JSON.ARRTRIM', key, path, start.toString(), stop.toString()];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, path: RedisArgument, start: number, stop: number) {
|
||||
parser.push('JSON.ARRTRIM');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, start.toString(), stop.toString());
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import CLEAR from './CLEAR';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.CLEAR', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
CLEAR.transformArguments('key'),
|
||||
parseArgs(CLEAR, 'key'),
|
||||
['JSON.CLEAR', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
CLEAR.transformArguments('key', {
|
||||
parseArgs(CLEAR, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.CLEAR', 'key', '$']
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonClearOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: JsonClearOptions) {
|
||||
const args = ['JSON.CLEAR', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonClearOptions) {
|
||||
parser.push('JSON.CLEAR');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import DEBUG_MEMORY from './DEBUG_MEMORY';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.DEBUG MEMORY', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
DEBUG_MEMORY.transformArguments('key'),
|
||||
parseArgs(DEBUG_MEMORY, 'key'),
|
||||
['JSON.DEBUG', 'MEMORY', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
DEBUG_MEMORY.transformArguments('key', {
|
||||
parseArgs(DEBUG_MEMORY, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.DEBUG', 'MEMORY', 'key', '$']
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonDebugMemoryOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 2,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: JsonDebugMemoryOptions) {
|
||||
const args = ['JSON.DEBUG', 'MEMORY', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonDebugMemoryOptions) {
|
||||
parser.push('JSON.DEBUG', 'MEMORY');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import DEL from './DEL';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.DEL', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
DEL.transformArguments('key'),
|
||||
parseArgs(DEL, 'key'),
|
||||
['JSON.DEL', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
DEL.transformArguments('key', {
|
||||
parseArgs(DEL, 'key', {
|
||||
path: '$.path'
|
||||
}),
|
||||
['JSON.DEL', 'key', '$.path']
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonDelOptions {
|
||||
path?: RedisArgument
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: JsonDelOptions) {
|
||||
const args = ['JSON.DEL', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonDelOptions) {
|
||||
parser.push('JSON.DEL');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import FORGET from './FORGET';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.FORGET', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('key', () => {
|
||||
assert.deepEqual(
|
||||
FORGET.transformArguments('key'),
|
||||
parseArgs(FORGET, 'key'),
|
||||
['JSON.FORGET', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('key, path', () => {
|
||||
assert.deepEqual(
|
||||
FORGET.transformArguments('key', {
|
||||
parseArgs(FORGET, 'key', {
|
||||
path: '$.path'
|
||||
}),
|
||||
['JSON.FORGET', 'key', '$.path']
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonForgetOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: JsonForgetOptions) {
|
||||
const args = ['JSON.FORGET', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonForgetOptions) {
|
||||
parser.push('JSON.FORGET');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,12 +1,13 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import GET from './GET';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.GET', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
GET.transformArguments('key'),
|
||||
parseArgs(GET, 'key'),
|
||||
['JSON.GET', 'key']
|
||||
);
|
||||
});
|
||||
@@ -14,14 +15,14 @@ describe('JSON.GET', () => {
|
||||
describe('with path', () => {
|
||||
it('string', () => {
|
||||
assert.deepEqual(
|
||||
GET.transformArguments('key', { path: '$' }),
|
||||
parseArgs(GET, 'key', { path: '$' }),
|
||||
['JSON.GET', 'key', '$']
|
||||
);
|
||||
});
|
||||
|
||||
it('array', () => {
|
||||
assert.deepEqual(
|
||||
GET.transformArguments('key', { path: ['$.1', '$.2'] }),
|
||||
parseArgs(GET, 'key', { path: ['$.1', '$.2'] }),
|
||||
['JSON.GET', 'key', '$.1', '$.2']
|
||||
);
|
||||
});
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, Command } from '@redis/client/lib/RESP/types';
|
||||
import { RedisVariadicArgument } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { transformRedisJsonNullReply } from '.';
|
||||
|
||||
export interface JsonGetOptions {
|
||||
@@ -7,16 +8,13 @@ export interface JsonGetOptions {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: JsonGetOptions) {
|
||||
let args = ['JSON.GET', key];
|
||||
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonGetOptions) {
|
||||
parser.push('JSON.GET');
|
||||
parser.pushKey(key);
|
||||
if (options?.path !== undefined) {
|
||||
args = pushVariadicArguments(args, options.path);
|
||||
parser.pushVariadic(options.path)
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: transformRedisJsonNullReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MERGE from './MERGE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.MERGE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MERGE.transformArguments('key', '$', 'value'),
|
||||
parseArgs(MERGE, 'key', '$', 'value'),
|
||||
['JSON.MERGE', 'key', '$', '"value"']
|
||||
);
|
||||
});
|
||||
|
@@ -1,16 +1,13 @@
|
||||
import { SimpleStringReply, Command, RedisArgument } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { SimpleStringReply, Command, RedisArgument } from '@redis/client/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, value: RedisJSON) {
|
||||
return [
|
||||
'JSON.MERGE',
|
||||
key,
|
||||
path,
|
||||
transformRedisJsonArgument(value)
|
||||
];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, path: RedisArgument, value: RedisJSON) {
|
||||
parser.push('JSON.MERGE');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, transformRedisJsonArgument(value));
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MGET from './MGET';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.MGET', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MGET.transformArguments(['1', '2'], '$'),
|
||||
parseArgs(MGET, ['1', '2'], '$'),
|
||||
['JSON.MGET', '1', '2', '$']
|
||||
);
|
||||
});
|
||||
|
@@ -1,15 +1,13 @@
|
||||
import { RedisArgument, UnwrapReply, ArrayReply, NullReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, UnwrapReply, ArrayReply, NullReply, BlobStringReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { transformRedisJsonNullReply } from '.';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(keys: Array<RedisArgument>, path: RedisArgument) {
|
||||
return [
|
||||
'JSON.MGET',
|
||||
...keys,
|
||||
path
|
||||
];
|
||||
parseCommand(parser: CommandParser, keys: Array<RedisArgument>, path: RedisArgument) {
|
||||
parser.push('JSON.MGET');
|
||||
parser.pushKeys(keys);
|
||||
parser.push(path);
|
||||
},
|
||||
transformReply(reply: UnwrapReply<ArrayReply<NullReply | BlobStringReply>>) {
|
||||
return reply.map(json => transformRedisJsonNullReply(json))
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import MSET from './MSET';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.MSET', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
MSET.transformArguments([{
|
||||
parseArgs(MSET, [{
|
||||
key: '1',
|
||||
path: '$',
|
||||
value: 1
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export interface JsonMSetItem {
|
||||
@@ -8,21 +9,14 @@ export interface JsonMSetItem {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(items: Array<JsonMSetItem>) {
|
||||
const args = new Array<RedisArgument>(1 + items.length * 3);
|
||||
args[0] = 'JSON.MSET';
|
||||
parseCommand(parser: CommandParser, items: Array<JsonMSetItem>) {
|
||||
parser.push('JSON.MSET');
|
||||
|
||||
let argsIndex = 1;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
args[argsIndex++] = item.key;
|
||||
args[argsIndex++] = item.path;
|
||||
args[argsIndex++] = transformRedisJsonArgument(item.value);
|
||||
parser.pushKey(items[i].key);
|
||||
parser.push(items[i].path, transformRedisJsonArgument(items[i].value));
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import NUMINCRBY from './NUMINCRBY';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.NUMINCRBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
NUMINCRBY.transformArguments('key', '$', 1),
|
||||
parseArgs(NUMINCRBY, 'key', '$', 1),
|
||||
['JSON.NUMINCRBY', 'key', '$', '1']
|
||||
);
|
||||
});
|
||||
|
@@ -1,10 +1,12 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, DoubleReply, NullReply, BlobStringReply, UnwrapReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, NumberReply, DoubleReply, NullReply, BlobStringReply, UnwrapReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
|
||||
return ['JSON.NUMINCRBY', key, path, by.toString()];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, path: RedisArgument, by: number) {
|
||||
parser.push('JSON.NUMINCRBY');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, by.toString());
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: UnwrapReply<BlobStringReply>) => {
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import NUMMULTBY from './NUMMULTBY';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.NUMMULTBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
NUMMULTBY.transformArguments('key', '$', 2),
|
||||
parseArgs(NUMMULTBY, 'key', '$', 2),
|
||||
['JSON.NUMMULTBY', 'key', '$', '2']
|
||||
);
|
||||
});
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, Command } from '@redis/client/lib/RESP/types';
|
||||
import NUMINCRBY from './NUMINCRBY';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
|
||||
return ['JSON.NUMMULTBY', key, path, by.toString()];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, path: RedisArgument, by: number) {
|
||||
parser.push('JSON.NUMMULTBY');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, by.toString());
|
||||
},
|
||||
transformReply: NUMINCRBY.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import OBJKEYS from './OBJKEYS';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.OBJKEYS', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
OBJKEYS.transformArguments('key'),
|
||||
parseArgs(OBJKEYS, 'key'),
|
||||
['JSON.OBJKEYS', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
OBJKEYS.transformArguments('key', {
|
||||
parseArgs(OBJKEYS, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.OBJKEYS', 'key', '$']
|
||||
|
@@ -1,20 +1,18 @@
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonObjKeysOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, options?: JsonObjKeysOptions) {
|
||||
const args = ['JSON.OBJKEYS', key];
|
||||
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonObjKeysOptions) {
|
||||
parser.push('JSON.OBJKEYS');
|
||||
parser.pushKey(key);
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply> | ArrayReply<ArrayReply<BlobStringReply> | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import OBJLEN from './OBJLEN';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.OBJLEN', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
OBJLEN.transformArguments('key'),
|
||||
parseArgs(OBJLEN, 'key'),
|
||||
['JSON.OBJLEN', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
OBJLEN.transformArguments('key', {
|
||||
parseArgs(OBJLEN, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.OBJLEN', 'key', '$']
|
||||
|
@@ -1,20 +1,18 @@
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonObjLenOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, options?: JsonObjLenOptions) {
|
||||
const args = ['JSON.OBJLEN', key];
|
||||
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonObjLenOptions) {
|
||||
parser.push('JSON.OBJLEN');
|
||||
parser.pushKey(key);
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './RESP';
|
||||
import RESP from './RESP';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('RESP', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key'),
|
||||
parseArgs(RESP, 'key'),
|
||||
['JSON.RESP', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$'),
|
||||
parseArgs(RESP, 'key', '$'),
|
||||
['JSON.RESP', 'key', '$']
|
||||
);
|
||||
});
|
||||
|
@@ -1,15 +1,16 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(key: string, path?: string): Array<string> {
|
||||
const args = ['JSON.RESP', key];
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
import { CommandParser } from "@redis/client/lib/client/parser";
|
||||
import { Command, RedisArgument } from "@redis/client/lib/RESP/types";
|
||||
|
||||
type RESPReply = Array<string | number | RESPReply>;
|
||||
|
||||
export declare function transformReply(): RESPReply;
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, path?: string) {
|
||||
parser.push('JSON.RESP');
|
||||
parser.pushKey(key);
|
||||
if (path !== undefined) {
|
||||
parser.push(path);
|
||||
}
|
||||
},
|
||||
transformReply: undefined as unknown as () => RESPReply
|
||||
} as const satisfies Command;
|
@@ -1,26 +1,27 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import SET from './SET';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.SET', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
SET.transformArguments('key', '$', 'json'),
|
||||
parseArgs(SET, 'key', '$', 'json'),
|
||||
['JSON.SET', 'key', '$', '"json"']
|
||||
);
|
||||
});
|
||||
|
||||
it('NX', () => {
|
||||
assert.deepEqual(
|
||||
SET.transformArguments('key', '$', 'json', { NX: true }),
|
||||
parseArgs(SET, 'key', '$', 'json', { NX: true }),
|
||||
['JSON.SET', 'key', '$', '"json"', 'NX']
|
||||
);
|
||||
});
|
||||
|
||||
it('XX', () => {
|
||||
assert.deepEqual(
|
||||
SET.transformArguments('key', '$', 'json', { XX: true }),
|
||||
parseArgs(SET, 'key', '$', 'json', { XX: true }),
|
||||
['JSON.SET', 'key', '$', '"json"', 'XX']
|
||||
);
|
||||
});
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export interface JsonSetOptions {
|
||||
@@ -14,25 +15,25 @@ export interface JsonSetOptions {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
path: RedisArgument,
|
||||
json: RedisJSON,
|
||||
options?: JsonSetOptions
|
||||
) {
|
||||
const args = ['JSON.SET', key, path, transformRedisJsonArgument(json)];
|
||||
parser.push('JSON.SET');
|
||||
parser.pushKey(key);
|
||||
parser.push(path, transformRedisJsonArgument(json));
|
||||
|
||||
if (options?.condition) {
|
||||
args.push(options?.condition);
|
||||
parser.push(options?.condition);
|
||||
} else if (options?.NX) {
|
||||
args.push('NX');
|
||||
parser.push('NX');
|
||||
} else if (options?.XX) {
|
||||
args.push('XX');
|
||||
parser.push('XX');
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'> | NullReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import STRAPPEND from './STRAPPEND';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.STRAPPEND', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
STRAPPEND.transformArguments('key', 'append'),
|
||||
parseArgs(STRAPPEND, 'key', 'append'),
|
||||
['JSON.STRAPPEND', 'key', '"append"']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
STRAPPEND.transformArguments('key', 'append', {
|
||||
parseArgs(STRAPPEND, 'key', 'append', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.STRAPPEND', 'key', '$', '"append"']
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { RedisArgument, Command, NullReply, NumberReply, ArrayReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, Command, NullReply, NumberReply, ArrayReply } from '@redis/client/lib/RESP/types';
|
||||
import { transformRedisJsonArgument } from '.';
|
||||
|
||||
export interface JsonStrAppendOptions {
|
||||
@@ -6,17 +7,16 @@ export interface JsonStrAppendOptions {
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, append: string, options?: JsonStrAppendOptions) {
|
||||
const args = ['JSON.STRAPPEND', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, append: string, options?: JsonStrAppendOptions) {
|
||||
parser.push('JSON.STRAPPEND');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.path !== undefined) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
args.push(transformRedisJsonArgument(append));
|
||||
return args;
|
||||
parser.push(transformRedisJsonArgument(append));
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NullReply | NumberReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import STRLEN from './STRLEN';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.STRLEN', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
STRLEN.transformArguments('key'),
|
||||
parseArgs(STRLEN, 'key'),
|
||||
['JSON.STRLEN', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
STRLEN.transformArguments('key', {
|
||||
parseArgs(STRLEN, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.STRLEN', 'key', '$']
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonStrLenOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, options?: JsonStrLenOptions) {
|
||||
const args = ['JSON.STRLEN', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonStrLenOptions) {
|
||||
parser.push('JSON.STRLEN');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.path) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import TOGGLE from './TOGGLE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.TOGGLE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
TOGGLE.transformArguments('key', '$'),
|
||||
parseArgs(TOGGLE, 'key', '$'),
|
||||
['JSON.TOGGLE', 'key', '$']
|
||||
);
|
||||
});
|
||||
|
@@ -1,10 +1,12 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument) {
|
||||
return ['JSON.TOGGLE', key, path];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, path: RedisArgument) {
|
||||
parser.push('JSON.TOGGLE');
|
||||
parser.pushKey(key);
|
||||
parser.push(path);
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import TYPE from './TYPE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
describe('JSON.TYPE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
TYPE.transformArguments('key'),
|
||||
parseArgs(TYPE, 'key'),
|
||||
['JSON.TYPE', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
TYPE.transformArguments('key', {
|
||||
parseArgs(TYPE, 'key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.TYPE', 'key', '$']
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { NullReply, BlobStringReply, ArrayReply, Command, RedisArgument, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { CommandParser } from '@redis/client/lib/client/parser';
|
||||
import { NullReply, BlobStringReply, ArrayReply, Command, RedisArgument, UnwrapReply } from '@redis/client/lib/RESP/types';
|
||||
|
||||
export interface JsonTypeOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, options?: JsonTypeOptions) {
|
||||
const args = ['JSON.TYPE', key];
|
||||
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonTypeOptions) {
|
||||
parser.push('JSON.TYPE');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.path) {
|
||||
args.push(options.path);
|
||||
parser.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: {
|
||||
2: undefined as unknown as () => NullReply | BlobStringReply | ArrayReply<BlobStringReply | NullReply>,
|
||||
@@ -24,4 +23,3 @@ export default {
|
||||
}
|
||||
},
|
||||
} as const satisfies Command;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { BlobStringReply, NullReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import { BlobStringReply, NullReply, UnwrapReply } from '@redis/client/lib/RESP/types';
|
||||
import ARRAPPEND from './ARRAPPEND';
|
||||
import ARRINDEX from './ARRINDEX';
|
||||
import ARRINSERT from './ARRINSERT';
|
||||
@@ -23,7 +23,7 @@ import STRAPPEND from './STRAPPEND';
|
||||
import STRLEN from './STRLEN';
|
||||
import TOGGLE from './TOGGLE';
|
||||
import TYPE from './TYPE';
|
||||
import { isNullReply } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { isNullReply } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
export default {
|
||||
ARRAPPEND,
|
||||
|
Reference in New Issue
Block a user