diff --git a/packages/json/lib/commands/MSET.spec.ts b/packages/json/lib/commands/MSET.spec.ts new file mode 100644 index 0000000000..a8ecf9eabd --- /dev/null +++ b/packages/json/lib/commands/MSET.spec.ts @@ -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); +}); diff --git a/packages/json/lib/commands/MSET.ts b/packages/json/lib/commands/MSET.ts new file mode 100644 index 0000000000..ea553f4e88 --- /dev/null +++ b/packages/json/lib/commands/MSET.ts @@ -0,0 +1,24 @@ +import { RedisJSON, transformRedisJsonArgument } from "."; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments( + keys: Array, + path: string, + json: Array +): Array { + + if (keys.length != json.length) + throw new Error("Number of keys and json objects must be equal"); + + let args: Array = ["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;