You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
some json and search commands
This commit is contained in:
@@ -4,7 +4,7 @@ import DEBUG_MEMORY from './DEBUG_MEMORY';
|
||||
|
||||
describe('JSON.DEBUG MEMORY', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
DEBUG_MEMORY.transformArguments('key'),
|
||||
['JSON.DEBUG', 'MEMORY', 'key']
|
||||
@@ -13,7 +13,9 @@ describe('JSON.DEBUG MEMORY', () => {
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
DEBUG_MEMORY.transformArguments('key', '$'),
|
||||
DEBUG_MEMORY.transformArguments('key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.DEBUG', 'MEMORY', 'key', '$']
|
||||
);
|
||||
});
|
||||
@@ -21,7 +23,7 @@ describe('JSON.DEBUG MEMORY', () => {
|
||||
|
||||
testUtils.testWithClient('client.json.debugMemory', async client => {
|
||||
assert.deepEqual(
|
||||
await client.json.debugMemory('key', '$'),
|
||||
await client.json.debugMemory('key'),
|
||||
0
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
@@ -1,13 +1,17 @@
|
||||
import { RedisArgument, NumberReply, ArrayReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export interface JsonDebugMemoryOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 2,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||
transformArguments(key: RedisArgument, options?: JsonDebugMemoryOptions) {
|
||||
const args = ['JSON.DEBUG', 'MEMORY', key];
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
if (options?.path) {
|
||||
args.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
|
@@ -4,7 +4,7 @@ import OBJKEYS from './OBJKEYS';
|
||||
|
||||
describe('JSON.OBJKEYS', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
OBJKEYS.transformArguments('key'),
|
||||
['JSON.OBJKEYS', 'key']
|
||||
@@ -13,7 +13,9 @@ describe('JSON.OBJKEYS', () => {
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
OBJKEYS.transformArguments('key', '$'),
|
||||
OBJKEYS.transformArguments('key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.OBJKEYS', 'key', '$']
|
||||
);
|
||||
});
|
||||
@@ -21,7 +23,7 @@ describe('JSON.OBJKEYS', () => {
|
||||
|
||||
testUtils.testWithClient('client.json.objKeys', async client => {
|
||||
assert.deepEqual(
|
||||
await client.json.objKeys('key', '$'),
|
||||
await client.json.objKeys('key'),
|
||||
[null]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
@@ -1,13 +1,17 @@
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export interface JsonObjKeysOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||
transformArguments(key: RedisArgument, options?: JsonObjKeysOptions) {
|
||||
const args = ['JSON.OBJKEYS', key];
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
if (options?.path) {
|
||||
args.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
|
@@ -4,7 +4,7 @@ import OBJLEN from './OBJLEN';
|
||||
|
||||
describe('JSON.OBJLEN', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
OBJLEN.transformArguments('key'),
|
||||
['JSON.OBJLEN', 'key']
|
||||
@@ -13,7 +13,9 @@ describe('JSON.OBJLEN', () => {
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
OBJLEN.transformArguments('key', '$'),
|
||||
OBJLEN.transformArguments('key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.OBJLEN', 'key', '$']
|
||||
);
|
||||
});
|
||||
@@ -21,8 +23,8 @@ describe('JSON.OBJLEN', () => {
|
||||
|
||||
testUtils.testWithClient('client.json.objLen', async client => {
|
||||
assert.equal(
|
||||
await client.json.objLen('key', '$'),
|
||||
[null]
|
||||
await client.json.objLen('key'),
|
||||
null
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,13 +1,17 @@
|
||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export interface JsonObjLenOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||
transformArguments(key: RedisArgument, options?: JsonObjLenOptions) {
|
||||
const args = ['JSON.OBJLEN', key];
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
if (options?.path) {
|
||||
args.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
|
@@ -1,23 +1,34 @@
|
||||
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export interface NX {
|
||||
NX: true;
|
||||
}
|
||||
|
||||
export interface XX {
|
||||
XX: true;
|
||||
export interface JsonSetOptions {
|
||||
condition?: 'NX' | 'XX';
|
||||
/**
|
||||
* @deprecated Use `{ condition: 'NX' }` instead.
|
||||
*/
|
||||
NX?: boolean;
|
||||
/**
|
||||
* @deprecated Use `{ condition: 'XX' }` instead.
|
||||
*/
|
||||
XX?: boolean;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, json: RedisJSON, options?: NX | XX) {
|
||||
transformArguments(
|
||||
key: RedisArgument,
|
||||
path: RedisArgument,
|
||||
json: RedisJSON,
|
||||
options?: JsonSetOptions
|
||||
) {
|
||||
const args = ['JSON.SET', key, path, transformRedisJsonArgument(json)];
|
||||
|
||||
if ((<NX>options)?.NX) {
|
||||
if (options?.condition) {
|
||||
args.push(options?.condition);
|
||||
} else if (options?.NX) {
|
||||
args.push('NX');
|
||||
} else if ((<XX>options)?.XX) {
|
||||
} else if (options?.XX) {
|
||||
args.push('XX');
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import STRLEN from './STRLEN';
|
||||
|
||||
describe('JSON.STRLEN', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
STRLEN.transformArguments('key'),
|
||||
['JSON.STRLEN', 'key']
|
||||
@@ -13,7 +13,9 @@ describe('JSON.STRLEN', () => {
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
STRLEN.transformArguments('key', '$'),
|
||||
STRLEN.transformArguments('key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.STRLEN', 'key', '$']
|
||||
);
|
||||
});
|
||||
@@ -22,9 +24,9 @@ describe('JSON.STRLEN', () => {
|
||||
testUtils.testWithClient('client.json.strLen', async client => {
|
||||
const [, reply] = await Promise.all([
|
||||
client.json.set('key', '$', ''),
|
||||
client.json.strLen('key', '$')
|
||||
client.json.strLen('key')
|
||||
]);
|
||||
|
||||
assert.deepEqual(reply, [0]);
|
||||
assert.deepEqual(reply, 0);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,13 +1,17 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export interface JsonStrLenOptions {
|
||||
path?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, options?: JsonStrLenOptions) {
|
||||
const args = ['JSON.STRLEN', key];
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
if (options?.path) {
|
||||
args.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
|
@@ -3,20 +3,11 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import TOGGLE from './TOGGLE';
|
||||
|
||||
describe('JSON.TOGGLE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
assert.deepEqual(
|
||||
TOGGLE.transformArguments('key'),
|
||||
['JSON.TOGGLE', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
TOGGLE.transformArguments('key', '$'),
|
||||
['JSON.TOGGLE', 'key', '$']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
TOGGLE.transformArguments('key', '$'),
|
||||
['JSON.TOGGLE', 'key', '$']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.toggle', async client => {
|
||||
|
@@ -3,14 +3,8 @@ import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@re
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||
const args = ['JSON.TOGGLE', key]
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
}
|
||||
|
||||
return args;
|
||||
transformArguments(key: RedisArgument, path: RedisArgument) {
|
||||
return ['JSON.TOGGLE', key, path];
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,28 +1,32 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './TYPE';
|
||||
import TYPE from './TYPE';
|
||||
|
||||
describe('TYPE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key'),
|
||||
['JSON.TYPE', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$'),
|
||||
['JSON.TYPE', 'key', '$']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key'),
|
||||
['JSON.TYPE', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
// testUtils.testWithClient('client.json.type', async client => {
|
||||
// assert.deepEqual(
|
||||
// await client.json.type('key', '$'),
|
||||
// [null]
|
||||
// );
|
||||
// }, GLOBAL.SERVERS.OPEN);
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.TYPE', 'key', '$']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.type', async client => {
|
||||
assert.deepEqual(
|
||||
await client.json.type('key', {
|
||||
path: '$'
|
||||
}),
|
||||
[null]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,13 +1,25 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
import { NullReply, BlobStringReply, ArrayReply, Command, RedisArgument } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export function transformArguments(key: string, path?: string): Array<string> {
|
||||
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];
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
if (options?.path) {
|
||||
args.push(options.path);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
},
|
||||
transformReply: {
|
||||
2: undefined as unknown as () => NullReply | BlobStringReply | ArrayReply<BlobStringReply>,
|
||||
// TODO: ?!??!
|
||||
3: undefined as unknown as () => any
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
||||
export declare function transformReply(): string | null | Array<string | null>;
|
||||
|
@@ -19,7 +19,7 @@ import SET from './SET';
|
||||
import STRAPPEND from './STRAPPEND';
|
||||
import STRLEN from './STRLEN';
|
||||
import TOGGLE from './TOGGLE';
|
||||
// import TYPE from './TYPE';
|
||||
import TYPE from './TYPE';
|
||||
|
||||
export default {
|
||||
ARRAPPEND,
|
||||
@@ -64,8 +64,8 @@ export default {
|
||||
strLen: STRLEN,
|
||||
TOGGLE,
|
||||
toggle: TOGGLE,
|
||||
// TYPE,
|
||||
// type: TYPE
|
||||
TYPE,
|
||||
type: TYPE
|
||||
};
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||
|
Reference in New Issue
Block a user