diff --git a/packages/json/lib/commands/MSET.spec.ts b/packages/json/lib/commands/MSET.spec.ts new file mode 100644 index 00000000000..53d4d822505 --- /dev/null +++ b/packages/json/lib/commands/MSET.spec.ts @@ -0,0 +1,35 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './MSET'; + +describe('MSET', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments([{ + key: '1', + path: '$', + value: 1 + }, { + key: '2', + path: '$', + value: '2' + }]), + ['JSON.MSET', '1', '$', '1', '2', '$', '"2"'] + ); + }); + + testUtils.testWithClient('client.json.mSet', async client => { + assert.deepEqual( + await client.json.mSet([{ + key: '1', + path: '$', + value: 1 + }, { + key: '2', + path: '$', + value: '2' + }]), + 'OK' + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/json/lib/commands/MSET.ts b/packages/json/lib/commands/MSET.ts new file mode 100644 index 00000000000..67228f264d2 --- /dev/null +++ b/packages/json/lib/commands/MSET.ts @@ -0,0 +1,28 @@ +import { RedisJSON, transformRedisJsonArgument } from '.'; +import { RedisCommandArgument } from '@redis/client/dist/lib/commands'; + +export const FIRST_KEY_INDEX = 1; + +interface JsonMSetItem { + key: RedisCommandArgument; + path: RedisCommandArgument; + value: RedisJSON; +} + +export function transformArguments(items: Array): Array { + + const args = new Array(1 + items.length * 3); + args[0] = 'JSON.MSET'; + + let argsIndex = 1; + for (let i = 0; i < items.length; i++) { + const item = items[i]; + args[argsIndex++] = item.key; + args[argsIndex++] = item.path; + args[argsIndex++] = transformRedisJsonArgument(item.value); + } + + return args; +} + +export declare function transformReply(): 'OK'; diff --git a/packages/json/lib/commands/index.ts b/packages/json/lib/commands/index.ts index efcf156b84d..a42ece5f277 100644 --- a/packages/json/lib/commands/index.ts +++ b/packages/json/lib/commands/index.ts @@ -9,6 +9,7 @@ import * as DEL from './DEL'; import * as FORGET from './FORGET'; import * as GET from './GET'; import * as MGET from './MGET'; +import * as MSET from './MSET'; import * as NUMINCRBY from './NUMINCRBY'; import * as NUMMULTBY from './NUMMULTBY'; import * as OBJKEYS from './OBJKEYS'; @@ -42,6 +43,8 @@ export default { get: GET, MGET, mGet: MGET, + MSET, + mSet: MSET, NUMINCRBY, numIncrBy: NUMINCRBY, NUMMULTBY,