diff --git a/packages/json/lib/commands/MERGE.spec.ts b/packages/json/lib/commands/MERGE.spec.ts new file mode 100644 index 00000000000..ee5e6fff86d --- /dev/null +++ b/packages/json/lib/commands/MERGE.spec.ts @@ -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); +}); diff --git a/packages/json/lib/commands/MERGE.ts b/packages/json/lib/commands/MERGE.ts new file mode 100644 index 00000000000..81cce7f006b --- /dev/null +++ b/packages/json/lib/commands/MERGE.ts @@ -0,0 +1,9 @@ +import { RedisJSON, transformRedisJsonArgument } from '.'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string, path: string, json: RedisJSON): Array { + return ['JSON.MERGE', key, path, transformRedisJsonArgument(json)]; +} + +export declare function transformReply(): 'OK'; diff --git a/packages/json/lib/commands/index.ts b/packages/json/lib/commands/index.ts index a42ece5f277..9d0a82ec271 100644 --- a/packages/json/lib/commands/index.ts +++ b/packages/json/lib/commands/index.ts @@ -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'; @@ -41,6 +42,8 @@ export default { forget: FORGET, GET, get: GET, + MERGE, + merge: MERGE, MGET, mGet: MGET, MSET,