You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Added MSET command
MSET command added. Requires all keys to have the same JSON Path, which might fit most use cases, but is a limitation. Optionally we could make the path an array as well to support all use cases.
This commit is contained in:
19
packages/json/lib/commands/MSET.spec.ts
Normal file
19
packages/json/lib/commands/MSET.spec.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './MSET';
|
||||
|
||||
describe('MSET', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(['1', '2'], '$', [{ a: 1 }, { b: 2 }]),
|
||||
['JSON.MSET', '1', '$', '{ "a":"1" } ', '2', '$', '{ "b":"2"} ']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.mGet', async client => {
|
||||
assert.deepEqual(
|
||||
await client.json.mGet(["1", "2"], "$", [{ a: 1 }, { b: 2 }]),
|
||||
[null, null]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
24
packages/json/lib/commands/MSET.ts
Normal file
24
packages/json/lib/commands/MSET.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { RedisJSON, transformRedisJsonArgument } from ".";
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
keys: Array<string>,
|
||||
path: string,
|
||||
json: Array<RedisJSON>
|
||||
): Array<string> {
|
||||
|
||||
if (keys.length != json.length)
|
||||
throw new Error("Number of keys and json objects must be equal");
|
||||
|
||||
let args: Array<string> = ["JSON.SET"];
|
||||
|
||||
// walk through the key array, adding the key, the path and the json objects, calling transformRedisJsonArgument for each
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
args.push(keys[i], path, transformRedisJsonArgument(json[i]));
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): "OK" | null;
|
Reference in New Issue
Block a user