1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Merge branch 'v5' of github.com:leibale/node-redis into v5

This commit is contained in:
Leibale
2023-07-11 12:11:38 -04:00
25 changed files with 361 additions and 294 deletions

View File

@@ -1,5 +1,5 @@
import { RedisJSON, transformRedisJsonArgument } from '.'; import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisArgument, ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
export default { export default {
FIRST_KEY_INDEX: 1, FIRST_KEY_INDEX: 1,
@@ -13,5 +13,5 @@ export default {
return args; return args;
}, },
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply> transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
} as const satisfies Command; } as const satisfies Command;

View File

@@ -1,4 +1,4 @@
import { RedisArgument, ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.'; import { RedisJSON, transformRedisJsonArgument } from '.';
export default { export default {
@@ -23,5 +23,5 @@ export default {
return args; return args;
}, },
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply> transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
} as const satisfies Command; } as const satisfies Command;

View File

@@ -1,30 +1,30 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ARRINSERT'; import ARRINSERT from './ARRINSERT';
describe('ARRINSERT', () => { describe('JSON.ARRINSERT', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('single JSON', () => { it('single JSON', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '$', 0, 'json'), ARRINSERT.transformArguments('key', '$', 0, 'json'),
['JSON.ARRINSERT', 'key', '$', '0', '"json"'] ['JSON.ARRINSERT', 'key', '$', '0', '"json"']
); );
});
it('multiple JSONs', () => {
assert.deepEqual(
transformArguments('key', '$', 0, '1', '2'),
['JSON.ARRINSERT', 'key', '$', '0', '"1"', '"2"']
);
});
}); });
testUtils.testWithClient('client.json.arrInsert', async client => { it('multiple JSONs', () => {
await client.json.set('key', '$', []); assert.deepEqual(
ARRINSERT.transformArguments('key', '$', 0, '1', '2'),
['JSON.ARRINSERT', 'key', '$', '0', '"1"', '"2"']
);
});
});
assert.deepEqual( testUtils.testWithClient('client.json.arrInsert', async client => {
await client.json.arrInsert('key', '$', 0, 'json'), await client.json.set('key', '$', []);
[1]
); assert.deepEqual(
}, GLOBAL.SERVERS.OPEN); await client.json.arrInsert('key', '$', 0, 'json'),
[1]
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,15 +1,17 @@
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.'; import { RedisJSON, transformRedisJsonArgument } from '.';
export const FIRST_KEY_INDEX = 1; export default {
FIRST_KEY_INDEX: 1,
export function transformArguments(key: string, path: string, index: number, ...jsons: Array<RedisJSON>): Array<string> { IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path: RedisArgument, index: number, ...jsons: Array<RedisJSON>) {
const args = ['JSON.ARRINSERT', key, path, index.toString()]; const args = ['JSON.ARRINSERT', key, path, index.toString()];
for (const json of jsons) { for (const json of jsons) {
args.push(transformRedisJsonArgument(json)); args.push(transformRedisJsonArgument(json));
} }
return args; return args;
} },
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
export declare function transformReply(): number | Array<number>; } as const satisfies Command;

View File

@@ -1,30 +1,30 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ARRLEN'; import ARRLEN from './ARRLEN';
describe('ARRLEN', () => { describe('JSON.ARRLEN', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('without path', () => { it('without path', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ARRLEN.transformArguments('key'),
['JSON.ARRLEN', 'key'] ['JSON.ARRLEN', 'key']
); );
});
it('with path', () => {
assert.deepEqual(
transformArguments('key', '$'),
['JSON.ARRLEN', 'key', '$']
);
});
}); });
testUtils.testWithClient('client.json.arrLen', async client => { it('with path', () => {
await client.json.set('key', '$', []); assert.deepEqual(
ARRLEN.transformArguments('key', '$'),
['JSON.ARRLEN', 'key', '$']
);
});
});
assert.deepEqual( testUtils.testWithClient('client.json.arrLen', async client => {
await client.json.arrLen('key', '$'), await client.json.set('key', '$', []);
[0]
); assert.deepEqual(
}, GLOBAL.SERVERS.OPEN); await client.json.arrLen('key', '$'),
[0]
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,15 +1,16 @@
export const FIRST_KEY_INDEX = 1; import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
export const IS_READ_ONLY = true; export default {
FIRST_KEY_INDEX: 1,
export function transformArguments(key: string, path?: string): Array<string> { IS_READ_ONLY: true,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.ARRLEN', key]; const args = ['JSON.ARRLEN', key];
if (path) { if (path) {
args.push(path); args.push(path);
} }
return args; return args;
} },
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
export declare function transformReply(): number | Array<number>; } as const satisfies Command;

View File

@@ -1,21 +1,21 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ARRTRIM'; import ARRTRIM from './ARRTRIM';
describe('ARRTRIM', () => { describe('JSON.ARRTRIM', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '$', 0, 1), ARRTRIM.transformArguments('key', '$', 0, 1),
['JSON.ARRTRIM', 'key', '$', '0', '1'] ['JSON.ARRTRIM', 'key', '$', '0', '1']
); );
}); });
testUtils.testWithClient('client.json.arrTrim', async client => { testUtils.testWithClient('client.json.arrTrim', async client => {
await client.json.set('key', '$', []); await client.json.set('key', '$', []);
assert.deepEqual( assert.deepEqual(
await client.json.arrTrim('key', '$', 0, 1), await client.json.arrTrim('key', '$', 0, 1),
[0] [0]
); );
}, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,7 +1,10 @@
export const FIRST_KEY_INDEX = 1; import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path: string, start: number, stop: number): Array<string> { 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()]; return ['JSON.ARRTRIM', key, path, start.toString(), stop.toString()];
} },
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
export declare function transformReply(): number | Array<number>; } as const satisfies Command;

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import CLEAR from './CLEAR'; import CLEAR from './CLEAR';
describe('CLEAR', () => { describe('JSON.CLEAR', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('key', () => { it('key', () => {
assert.deepEqual( assert.deepEqual(

View File

@@ -1,21 +1,21 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './NUMINCRBY'; import NUMINCRBY from './NUMINCRBY';
describe('NUMINCRBY', () => { describe('JSON.NUMINCRBY', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '$', 1), NUMINCRBY.transformArguments('key', '$', 1),
['JSON.NUMINCRBY', 'key', '$', '1'] ['JSON.NUMINCRBY', 'key', '$', '1']
); );
}); });
testUtils.testWithClient('client.json.numIncrBy', async client => { testUtils.testWithClient('client.json.numIncrBy', async client => {
await client.json.set('key', '$', 0); await client.json.set('key', '$', 0);
assert.deepEqual( assert.deepEqual(
await client.json.numIncrBy('key', '$', 1), await client.json.numIncrBy('key', '$', 1),
[1] [1]
); );
}, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,7 +1,10 @@
export const FIRST_KEY_INDEX = 1; import { RedisArgument, Command, ArrayReply, NumberReply, DoubleReply, NullReply } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path: string, by: number): Array<string> { export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
return ['JSON.NUMINCRBY', key, path, by.toString()]; return ['JSON.NUMINCRBY', key, path, by.toString()];
} },
transformReply: undefined as unknown as () => ArrayReply<NumberReply | DoubleReply | NullReply>
export { transformNumbersReply as transformReply } from '.'; } as const satisfies Command;

View File

@@ -1,21 +1,21 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './NUMMULTBY'; import NUMMULTBY from './NUMMULTBY';
describe('NUMMULTBY', () => { describe('JSON.NUMMULTBY', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '$', 2), NUMMULTBY.transformArguments('key', '$', 2),
['JSON.NUMMULTBY', 'key', '$', '2'] ['JSON.NUMMULTBY', 'key', '$', '2']
); );
}); });
testUtils.testWithClient('client.json.numMultBy', async client => { testUtils.testWithClient('client.json.numMultBy', async client => {
await client.json.set('key', '$', 1); await client.json.set('key', '$', 1);
assert.deepEqual( assert.deepEqual(
await client.json.numMultBy('key', '$', 2), await client.json.numMultBy('key', '$', 2),
[2] [2]
); );
}, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,7 +1,10 @@
export const FIRST_KEY_INDEX = 1; import { RedisArgument, Command, ArrayReply, NumberReply, DoubleReply, NullReply } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path: string, by: number): Array<string> { export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
return ['JSON.NUMMULTBY', key, path, by.toString()]; return ['JSON.NUMMULTBY', key, path, by.toString()];
} },
transformReply: undefined as unknown as () => ArrayReply<NumberReply | DoubleReply | NullReply>
export { transformNumbersReply as transformReply } from '.'; } as const satisfies Command;

View File

@@ -1,28 +1,28 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './OBJKEYS'; import OBJKEYS from './OBJKEYS';
describe('OBJKEYS', () => { describe('JSON.OBJKEYS', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('without path', () => { it('without path', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), OBJKEYS.transformArguments('key'),
['JSON.OBJKEYS', 'key'] ['JSON.OBJKEYS', 'key']
); );
});
it('with path', () => {
assert.deepEqual(
transformArguments('key', '$'),
['JSON.OBJKEYS', 'key', '$']
);
});
}); });
// testUtils.testWithClient('client.json.objKeys', async client => { it('with path', () => {
// assert.deepEqual( assert.deepEqual(
// await client.json.objKeys('key', '$'), OBJKEYS.transformArguments('key', '$'),
// [null] ['JSON.OBJKEYS', 'key', '$']
// ); );
// }, GLOBAL.SERVERS.OPEN); });
});
testUtils.testWithClient('client.json.objKeys', async client => {
assert.deepEqual(
await client.json.objKeys('key', '$'),
[null]
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,13 +1,18 @@
export const FIRST_KEY_INDEX = 1; import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path?: string): Array<string> { type ReplyItem = ArrayReply<BlobStringReply> | NullReply;
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.OBJKEYS', key]; const args = ['JSON.OBJKEYS', key];
if (path) { if (path) {
args.push(path); args.push(path);
} }
return args; return args;
} },
transformReply: undefined as unknown as () => ReplyItem | ArrayReply<ReplyItem>
export declare function transformReply(): Array<string> | null | Array<Array<string> | null>; } as const satisfies Command;

View File

@@ -1,28 +1,28 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './OBJLEN'; import OBJLEN from './OBJLEN';
describe('OBJLEN', () => { describe('JSON.OBJLEN', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('without path', () => { it('without path', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), OBJLEN.transformArguments('key'),
['JSON.OBJLEN', 'key'] ['JSON.OBJLEN', 'key']
); );
});
it('with path', () => {
assert.deepEqual(
transformArguments('key', '$'),
['JSON.OBJLEN', 'key', '$']
);
});
}); });
// testUtils.testWithClient('client.json.objLen', async client => { it('with path', () => {
// assert.equal( assert.deepEqual(
// await client.json.objLen('key', '$'), OBJLEN.transformArguments('key', '$'),
// [null] ['JSON.OBJLEN', 'key', '$']
// ); );
// }, GLOBAL.SERVERS.OPEN); });
});
// testUtils.testWithClient('client.json.objLen', async client => {
// assert.equal(
// await client.json.objLen('key', '$'),
// [null]
// );
// }, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,13 +1,16 @@
export const FIRST_KEY_INDEX = 1; import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path?: string): Array<string> { export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.OBJLEN', key]; const args = ['JSON.OBJLEN', key];
if (path) { if (path) {
args.push(path); args.push(path);
} }
return args; return args;
} },
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
export declare function transformReply(): number | null | Array<number | null>; } as const satisfies Command;

View File

@@ -1,35 +1,35 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SET'; import SET from './SET';
describe('SET', () => { describe('JSON.SET', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '$', 'json'), SET.transformArguments('key', '$', 'json'),
['JSON.SET', 'key', '$', '"json"'] ['JSON.SET', 'key', '$', '"json"']
); );
});
it('NX', () => {
assert.deepEqual(
transformArguments('key', '$', 'json', { NX: true }),
['JSON.SET', 'key', '$', '"json"', 'NX']
);
});
it('XX', () => {
assert.deepEqual(
transformArguments('key', '$', 'json', { XX: true }),
['JSON.SET', 'key', '$', '"json"', 'XX']
);
});
}); });
testUtils.testWithClient('client.json.mGet', async client => { it('NX', () => {
assert.equal( assert.deepEqual(
await client.json.set('key', '$', 'json'), SET.transformArguments('key', '$', 'json', { NX: true }),
'OK' ['JSON.SET', 'key', '$', '"json"', 'NX']
); );
}, GLOBAL.SERVERS.OPEN); });
it('XX', () => {
assert.deepEqual(
SET.transformArguments('key', '$', 'json', { XX: true }),
['JSON.SET', 'key', '$', '"json"', 'XX']
);
});
});
testUtils.testWithClient('client.json.set', async client => {
assert.equal(
await client.json.set('key', '$', 'json'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,25 +1,27 @@
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.'; import { RedisJSON, transformRedisJsonArgument } from '.';
export const FIRST_KEY_INDEX = 1; export interface NX {
NX: true;
interface NX {
NX: true;
} }
interface XX { export interface XX {
XX: true; XX: true;
} }
export function transformArguments(key: string, path: string, json: RedisJSON, options?: NX | XX): Array<string> { export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path: RedisArgument, json: RedisJSON, options?: NX | XX) {
const args = ['JSON.SET', key, path, transformRedisJsonArgument(json)]; const args = ['JSON.SET', key, path, transformRedisJsonArgument(json)];
if ((<NX>options)?.NX) { if ((<NX>options)?.NX) {
args.push('NX'); args.push('NX');
} else if ((<XX>options)?.XX) { } else if ((<XX>options)?.XX) {
args.push('XX'); args.push('XX');
} }
return args; return args;
} },
transformReply: undefined as unknown as () => SimpleStringReply<'OK'> | NullReply
export declare function transformReply(): 'OK' | null; } as const satisfies Command;

View File

@@ -1,30 +1,30 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './STRAPPEND'; // import { transformArguments } from './STRAPPEND';
describe('STRAPPEND', () => { // describe('STRAPPEND', () => {
describe('transformArguments', () => { // describe('transformArguments', () => {
it('without path', () => { // it('without path', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', 'append'), // transformArguments('key', 'append'),
['JSON.STRAPPEND', 'key', '"append"'] // ['JSON.STRAPPEND', 'key', '"append"']
); // );
}); // });
it('with path', () => { // it('with path', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', '$', 'append'), // transformArguments('key', '$', 'append'),
['JSON.STRAPPEND', 'key', '$', '"append"'] // ['JSON.STRAPPEND', 'key', '$', '"append"']
); // );
}); // });
}); // });
testUtils.testWithClient('client.json.strAppend', async client => { // testUtils.testWithClient('client.json.strAppend', async client => {
await client.json.set('key', '$', ''); // await client.json.set('key', '$', '');
assert.deepEqual( // assert.deepEqual(
await client.json.strAppend('key', '$', 'append'), // await client.json.strAppend('key', '$', 'append'),
[6] // [6]
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,21 +1,21 @@
import { transformRedisJsonArgument } from '.'; // import { transformRedisJsonArgument } from '.';
export const FIRST_KEY_INDEX = 1; // export const FIRST_KEY_INDEX = 1;
type AppendArguments = [key: string, append: string]; // type AppendArguments = [key: string, append: string];
type AppendWithPathArguments = [key: string, path: string, append: string]; // type AppendWithPathArguments = [key: string, path: string, append: string];
export function transformArguments(...[key, pathOrAppend, append]: AppendArguments | AppendWithPathArguments): Array<string> { // export function transformArguments(...[key, pathOrAppend, append]: AppendArguments | AppendWithPathArguments): Array<string> {
const args = ['JSON.STRAPPEND', key]; // const args = ['JSON.STRAPPEND', key];
if (append !== undefined && append !== null) { // if (append !== undefined && append !== null) {
args.push(pathOrAppend, transformRedisJsonArgument(append)); // args.push(pathOrAppend, transformRedisJsonArgument(append));
} else { // } else {
args.push(transformRedisJsonArgument(pathOrAppend)); // args.push(transformRedisJsonArgument(pathOrAppend));
} // }
return args; // return args;
} // }
export declare function transformReply(): number | Array<number>; // export declare function transformReply(): number | Array<number>;

View File

@@ -1,30 +1,30 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './STRLEN'; import STRLEN from './STRLEN';
describe('STRLEN', () => { describe('JSON.STRLEN', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('without path', () => { it('without path', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), STRLEN.transformArguments('key'),
['JSON.STRLEN', 'key'] ['JSON.STRLEN', 'key']
); );
});
it('with path', () => {
assert.deepEqual(
transformArguments('key', '$'),
['JSON.STRLEN', 'key', '$']
);
});
}); });
testUtils.testWithClient('client.json.strLen', async client => { it('with path', () => {
await client.json.set('key', '$', ''); assert.deepEqual(
STRLEN.transformArguments('key', '$'),
['JSON.STRLEN', 'key', '$']
);
});
});
assert.deepEqual( testUtils.testWithClient('client.json.strLen', async client => {
await client.json.strLen('key', '$'), await client.json.set('key', '$', '');
[0]
); assert.deepEqual(
}, GLOBAL.SERVERS.OPEN); await client.json.strLen('key', '$'),
[0]
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,15 +1,16 @@
export const FIRST_KEY_INDEX = 1; import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
export const IS_READ_ONLY = true; export default {
FIRST_KEY_INDEX: 1,
export function transformArguments(key: string, path?: string): Array<string> { IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.STRLEN', key]; const args = ['JSON.STRLEN', key];
if (path) { if (path) {
args.push(path); args.push(path);
} }
return args; return args;
} },
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
export declare function transformReply(): number; } as const satisfies Command;

View File

@@ -0,0 +1,30 @@
import { strict as assert } from 'assert';
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', '$']
);
});
});
testUtils.testWithClient('client.json.toggle', async client => {
await client.json.set('key', '$', '');
assert.deepEqual(
await client.json.toggle('key', '$'),
[0]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,14 @@
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@redis/client/dist/lib/RESP/types';
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.TOGGLE', key]
if (path) args.push(path);
return args;
},
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
} as const satisfies Command;