diff --git a/packages/json/lib/commands/CLEAR.spec.ts b/packages/json/lib/commands/CLEAR.spec.ts new file mode 100644 index 0000000000..ce8b289889 --- /dev/null +++ b/packages/json/lib/commands/CLEAR.spec.ts @@ -0,0 +1,28 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import CLEAR from './CLEAR'; + +describe('CLEAR', () => { + describe('transformArguments', () => { + it('key', () => { + assert.deepEqual( + CLEAR.transformArguments('key'), + ['JSON.CLEAR', 'key'] + ); + }); + + it('key, path', () => { + assert.deepEqual( + CLEAR.transformArguments('key', '$.path'), + ['JSON.CLEAR', 'key', '$.path'] + ); + }); + }); + + testUtils.testWithClient('client.json.clear', async client => { + assert.deepEqual( + await client.json.clear('key'), + 0 + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/json/lib/commands/CLEAR.ts b/packages/json/lib/commands/CLEAR.ts new file mode 100644 index 0000000000..a5730f5b4e --- /dev/null +++ b/packages/json/lib/commands/CLEAR.ts @@ -0,0 +1,14 @@ +import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; + +export default { + FIRST_KEY_INDEX: 1, + IS_READ_ONLY: false, + transformArguments(key: RedisArgument, path?: RedisArgument) { + const args = ['JSON.CLEAR', key]; + + if (path) args.push(path); + + return args; + }, + transformReply: undefined as unknown as () => NumberReply +} as const satisfies Command; diff --git a/packages/json/lib/commands/index.ts b/packages/json/lib/commands/index.ts index efcf156b84..218462f4db 100644 --- a/packages/json/lib/commands/index.ts +++ b/packages/json/lib/commands/index.ts @@ -1,6 +1,7 @@ import * as ARRAPPEND from './ARRAPPEND'; import * as ARRINDEX from './ARRINDEX'; import * as ARRINSERT from './ARRINSERT'; +import CLEAR from './CLEAR'; import * as ARRLEN from './ARRLEN'; import * as ARRPOP from './ARRPOP'; import * as ARRTRIM from './ARRTRIM'; @@ -26,6 +27,8 @@ export default { arrIndex: ARRINDEX, ARRINSERT, arrInsert: ARRINSERT, + CLEAR, + clear: CLEAR, ARRLEN, arrLen: ARRLEN, ARRPOP,