Skip to content

Commit cf21c1a

Browse files
shacharPashleibale
andauthored
Add support for JSON.MERGE (#2511)
* Support JSON.MERGE Command * test only 2.6+ ReJson version * test on edge * review * Update test-utils.ts --------- Co-authored-by: Leibale Eidelman <[email protected]>
1 parent 8c8740a commit cf21c1a

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './MERGE';
4+
5+
describe('MERGE', () => {
6+
testUtils.isVersionGreaterThanHook([2, 6]);
7+
8+
it('transformArguments', () => {
9+
assert.deepEqual(
10+
transformArguments('key', '$', 1),
11+
['JSON.MERGE', 'key', '$', '1']
12+
);
13+
});
14+
15+
testUtils.testWithClient('client.json.merge', async client => {
16+
assert.equal(
17+
await client.json.merge('key', '$', 'json'),
18+
'OK'
19+
);
20+
}, GLOBAL.SERVERS.OPEN);
21+
});

packages/json/lib/commands/MERGE.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { RedisJSON, transformRedisJsonArgument } from '.';
2+
3+
export const FIRST_KEY_INDEX = 1;
4+
5+
export function transformArguments(key: string, path: string, json: RedisJSON): Array<string> {
6+
return ['JSON.MERGE', key, path, transformRedisJsonArgument(json)];
7+
}
8+
9+
export declare function transformReply(): 'OK';

packages/json/lib/commands/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as DEBUG_MEMORY from './DEBUG_MEMORY';
88
import * as DEL from './DEL';
99
import * as FORGET from './FORGET';
1010
import * as GET from './GET';
11+
import * as MERGE from './MERGE';
1112
import * as MGET from './MGET';
1213
import * as MSET from './MSET';
1314
import * as NUMINCRBY from './NUMINCRBY';
@@ -41,6 +42,8 @@ export default {
4142
forget: FORGET,
4243
GET,
4344
get: GET,
45+
MERGE,
46+
merge: MERGE,
4447
MGET,
4548
mGet: MGET,
4649
MSET,

0 commit comments

Comments
 (0)