Skip to content

Commit 4e47456

Browse files
Merge 0093eb0 into 294cbf8
2 parents 294cbf8 + 0093eb0 commit 4e47456

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Diff for: packages/json/lib/commands/MSET.spec.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './MSET';
4+
5+
describe('MSET', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments([{
9+
key: '1',
10+
path: '$',
11+
value: 1
12+
}, {
13+
key: '2',
14+
path: '$',
15+
value: '2'
16+
}]),
17+
['JSON.MSET', '1', '$', '1', '2', '$', '"2"']
18+
);
19+
});
20+
21+
testUtils.testWithClient('client.json.mSet', async client => {
22+
assert.deepEqual(
23+
await client.json.mSet([{
24+
key: '1',
25+
path: '$',
26+
value: 1
27+
}, {
28+
key: '2',
29+
path: '$',
30+
value: '2'
31+
}]),
32+
'OK'
33+
);
34+
}, GLOBAL.SERVERS.OPEN);
35+
});

Diff for: packages/json/lib/commands/MSET.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { RedisJSON, transformRedisJsonArgument } from '.';
2+
import { RedisCommandArgument } from '@redis/client/dist/lib/commands';
3+
4+
export const FIRST_KEY_INDEX = 1;
5+
6+
interface JsonMSetItem {
7+
key: RedisCommandArgument;
8+
path: RedisCommandArgument;
9+
value: RedisJSON;
10+
}
11+
12+
export function transformArguments(items: Array<JsonMSetItem>): Array<string> {
13+
14+
const args = new Array(1 + items.length * 3);
15+
args[0] = 'JSON.MSET';
16+
17+
let argsIndex = 1;
18+
for (let i = 0; i < items.length; i++) {
19+
const item = items[i];
20+
args[argsIndex++] = item.key;
21+
args[argsIndex++] = item.path;
22+
args[argsIndex++] = transformRedisJsonArgument(item.value);
23+
}
24+
25+
return args;
26+
}
27+
28+
export declare function transformReply(): 'OK';

Diff for: packages/json/lib/commands/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as DEL from './DEL';
99
import * as FORGET from './FORGET';
1010
import * as GET from './GET';
1111
import * as MGET from './MGET';
12+
import * as MSET from './MSET';
1213
import * as NUMINCRBY from './NUMINCRBY';
1314
import * as NUMMULTBY from './NUMMULTBY';
1415
import * as OBJKEYS from './OBJKEYS';
@@ -42,6 +43,8 @@ export default {
4243
get: GET,
4344
MGET,
4445
mGet: MGET,
46+
MSET,
47+
mSet: MSET,
4548
NUMINCRBY,
4649
numIncrBy: NUMINCRBY,
4750
NUMMULTBY,

0 commit comments

Comments
 (0)