Skip to content

Commit

Permalink
Add support for JSON.MERGE (#2511)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
shacharPash and leibale authored Sep 18, 2023
1 parent 8c8740a commit cf21c1a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/json/lib/commands/MERGE.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MERGE';

describe('MERGE', () => {
testUtils.isVersionGreaterThanHook([2, 6]);

it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', '$', 1),
['JSON.MERGE', 'key', '$', '1']
);
});

testUtils.testWithClient('client.json.merge', async client => {
assert.equal(
await client.json.merge('key', '$', 'json'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});
9 changes: 9 additions & 0 deletions packages/json/lib/commands/MERGE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RedisJSON, transformRedisJsonArgument } from '.';

export const FIRST_KEY_INDEX = 1;

export function transformArguments(key: string, path: string, json: RedisJSON): Array<string> {
return ['JSON.MERGE', key, path, transformRedisJsonArgument(json)];
}

export declare function transformReply(): 'OK';
3 changes: 3 additions & 0 deletions packages/json/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as DEBUG_MEMORY from './DEBUG_MEMORY';
import * as DEL from './DEL';
import * as FORGET from './FORGET';
import * as GET from './GET';
import * as MERGE from './MERGE';
import * as MGET from './MGET';
import * as MSET from './MSET';
import * as NUMINCRBY from './NUMINCRBY';
Expand Down Expand Up @@ -41,6 +42,8 @@ export default {
forget: FORGET,
GET,
get: GET,
MERGE,
merge: MERGE,
MGET,
mGet: MGET,
MSET,
Expand Down

0 comments on commit cf21c1a

Please sign in to comment.