Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/json/lib/commands/MSET.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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);
});
25 changes: 25 additions & 0 deletions packages/json/lib/commands/MSET.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { RedisJSON, transformRedisJsonArgument } from '.';

export const FIRST_KEY_INDEX = 1;

export interface KeyPathValue {
key: string;
path: string;
value: RedisJSON;
}

export function transformArguments(keyPathValues: Array<KeyPathValue>): Array<string> {
if (keyPathValues.length === 0) {
throw new Error('ERR wrong number of arguments for \'MSET\' command');
}

const args: string[] = ['JSON.MSET'];

keyPathValues.forEach(({ key, path, value }) => {
args.push(key, path, transformRedisJsonArgument(value));
});

return args;
}

export declare function transformReply(): 'OK' | null;
3 changes: 3 additions & 0 deletions packages/json/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,6 +43,8 @@ export default {
get: GET,
MGET,
mGet: MGET,
MSET,
mSet: MSET,
NUMINCRBY,
numIncrBy: NUMINCRBY,
NUMMULTBY,
Expand Down
3 changes: 2 additions & 1 deletion packages/json/lib/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down