diff --git a/packages/json/lib/commands/MSET.spec.ts b/packages/json/lib/commands/MSET.spec.ts new file mode 100644 index 00000000000..b271949dd9e --- /dev/null +++ b/packages/json/lib/commands/MSET.spec.ts @@ -0,0 +1,32 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './MSET'; + +describe('MSET', () => { + testUtils.isVersionGreaterThanHook([2, 6]); + + describe('transformArguments', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments([{ + key: 'key', + path: '$', + value: 'json' + }, { + key: 'key2', + path: '$', + value: 'json2' + }]), + ['JSON.MSET', 'key', '$', '"json"', 'key2', '$', '"json2"'] + ); + }); + }); + + + testUtils.testWithClient('client.json.mSet', async client => { + assert.equal( + await client.json.mSet([{ key: "key", path: "$", value: "json" }, { key: "key2", path: "$", value: "json2" }]), + '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..b116f136d6a --- /dev/null +++ b/packages/json/lib/commands/MSET.ts @@ -0,0 +1,22 @@ +import { RedisJSON, transformRedisJsonArgument} from '.'; +import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands'; + +export const FIRST_KEY_INDEX = 1; + +export interface KeyPathValue { + key: RedisCommandArgument; + path: RedisCommandArgument; + value: RedisJSON; +} + +export function transformArguments(keyPathValues: Array): RedisCommandArguments { + const args: RedisCommandArguments = ['JSON.MSET']; + + for (const { key, path, value } of keyPathValues) { + args.push(key, path, transformRedisJsonArgument(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, diff --git a/packages/json/lib/test-utils.ts b/packages/json/lib/test-utils.ts index f4c4e4eb201..97e189eed81 100644 --- a/packages/json/lib/test-utils.ts +++ b/packages/json/lib/test-utils.ts @@ -3,7 +3,8 @@ import RedisJSON from '.'; export default new TestUtils({ dockerImageName: 'redislabs/rejson', - dockerImageVersionArgument: 'rejson-version' + dockerImageVersionArgument: 'rejson-version', + defaultDockerVersion: 'edge' }); export const GLOBAL = {