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

change JSON.MSET signature, add to json command object, fix tests

This commit is contained in:
Leibale Eidelman
2023-08-29 11:21:34 -07:00
committed by GitHub
parent 132599332f
commit f476c38971
3 changed files with 41 additions and 19 deletions

View File

@@ -5,15 +5,31 @@ import { transformArguments } from './MSET';
describe('MSET', () => { describe('MSET', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(['1', '2'], '$', [{ a: 1 }, { b: 2 }]), transformArguments([{
['JSON.MSET', '1', '$', '{ "a":"1" } ', '2', '$', '{ "b":"2"} '] key: '1',
path: '$',
value: 1
}, {
key: '2',
path: '$',
value: '2'
}]),
['JSON.MSET', '1', '$', '1', '2', '$', '"2"']
); );
}); });
testUtils.testWithClient('client.json.mGet', async client => { testUtils.testWithClient('client.json.mSet', async client => {
assert.deepEqual( assert.deepEqual(
await client.json.mGet(["1", "2"], "$", [{ a: 1 }, { b: 2 }]), await client.json.mSet([{
[null, null] key: '1',
path: '$',
value: 1
}, {
key: '2',
path: '$',
value: '2'
}]),
'OK'
); );
}, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,24 +1,27 @@
import { RedisJSON, transformRedisJsonArgument } from "."; import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
export const FIRST_KEY_INDEX = 1; export const FIRST_KEY_INDEX = 1;
export function transformArguments( interface JsonMSetItem {
keys: Array<string>, key: RedisCommandArgument;
path: string, path: RedisCommandArgument;
json: Array<RedisJSON> value: RedisJSON;
): Array<string> { }
if (keys.length != json.length) export function transformArguments(items: Array<JsonMSetItem>): Array<string> {
throw new Error("Number of keys and json objects must be equal"); const args = new Array(1 + items.length * 3);
args[0] = 'JSON.MSET';
let args: Array<string> = ["JSON.SET"]; let argsIndex = 1;
for (let i = 0; i < items.length; i++) {
// walk through the key array, adding the key, the path and the json objects, calling transformRedisJsonArgument for each const item = items[i];
for (let i = 0; i < keys.length; i++) { args[argsIndex++] = item.key;
args.push(keys[i], path, transformRedisJsonArgument(json[i])); args[argsIndex++] = item.path;
args[argsIndex++] = transformRedisJsonArgument(item.json);
} }
return args; return args;
} }
export declare function transformReply(): "OK" | null; export declare function transformReply(): 'OK';

View File

@@ -9,6 +9,7 @@ import * as DEL from './DEL';
import * as FORGET from './FORGET'; import * as FORGET from './FORGET';
import * as GET from './GET'; import * as GET from './GET';
import * as MGET from './MGET'; import * as MGET from './MGET';
import * as MSET from './MSET';
import * as NUMINCRBY from './NUMINCRBY'; import * as NUMINCRBY from './NUMINCRBY';
import * as NUMMULTBY from './NUMMULTBY'; import * as NUMMULTBY from './NUMMULTBY';
import * as OBJKEYS from './OBJKEYS'; import * as OBJKEYS from './OBJKEYS';
@@ -42,6 +43,8 @@ export default {
get: GET, get: GET,
MGET, MGET,
mGet: MGET, mGet: MGET,
MSET,
mSet: MSET,
NUMINCRBY, NUMINCRBY,
numIncrBy: NUMINCRBY, numIncrBy: NUMINCRBY,
NUMMULTBY, NUMMULTBY,