diff --git a/packages/client/lib/commands/XSETID.spec.ts b/packages/client/lib/commands/XSETID.spec.ts index e69de29bb2..8e951335a8 100644 --- a/packages/client/lib/commands/XSETID.spec.ts +++ b/packages/client/lib/commands/XSETID.spec.ts @@ -0,0 +1,42 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import XSETID from './XSETID'; + +describe('XSETID', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + XSETID.transformArguments('key', '0-0'), + ['XSETID', 'key', '0-0'] + ); + }); + + it('with ENTRIESADDED', () => { + assert.deepEqual( + XSETID.transformArguments('key', '0-0', { + ENTRIESADDED: 1 + }), + ['XSETID', 'key', '0-0', 'ENTRIESADDED', '1'] + ); + }); + + it('with MAXDELETEDID', () => { + assert.deepEqual( + XSETID.transformArguments('key', '0-0', { + MAXDELETEDID: '1-1' + }), + ['XSETID', 'key', '0-0', 'MAXDELETEDID', '1-1'] + ); + }); + }); + + testUtils.testAll('xSetId', async client => { + assert.deepEqual( + await client.xSetId('key', '0-0'), + [] + ); + }, { + client: GLOBAL.SERVERS.OPEN, + cluster: GLOBAL.CLUSTERS.OPEN + }); +}); diff --git a/packages/client/lib/commands/XSETID.ts b/packages/client/lib/commands/XSETID.ts index df7cc10f90..bd3a8fd0bc 100644 --- a/packages/client/lib/commands/XSETID.ts +++ b/packages/client/lib/commands/XSETID.ts @@ -1,28 +1,29 @@ -// import { RedisCommandArgument, RedisCommandArguments } from '.'; +import { RedisArgument, SimpleStringReply, Command } from '../RESP/types'; +export interface XSetIdOptions { + ENTRIESADDED?: number; + MAXDELETEDID?: RedisArgument; +} -// export const FIRST_KEY_INDEX = 1; +export default { + FIRST_KEY_INDEX: 1, + IS_READ_ONLY: false, + transformArguments( + key: RedisArgument, + lastId: RedisArgument, + options?: XSetIdOptions + ) { + const args = ['XSETID', key, lastId]; -// interface XSetIdOptions { -// ENTRIESADDED?: number; -// MAXDELETEDID?: RedisCommandArgument; -// } + if (options?.ENTRIESADDED) { + args.push('ENTRIESADDED', options.ENTRIESADDED.toString()); + } -// export function transformArguments( -// key: RedisCommandArgument, -// lastId: RedisCommandArgument, -// options?: XSetIdOptions -// ): RedisCommandArguments { -// const args = ['XSETID', key, lastId]; + if (options?.MAXDELETEDID) { + args.push('MAXDELETEDID', options.MAXDELETEDID); + } -// if (options?.ENTRIESADDED) { -// args.push('ENTRIESADDED', options.ENTRIESADDED.toString()); -// } + return args; + }, + transformReply: undefined as unknown as () => SimpleStringReply<'OK'> +} as const satisfies Command; -// if (options?.MAXDELETEDID) { -// args.push('MAXDELETEDID', options.MAXDELETEDID); -// } - -// return args; -// } - -// export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/index.ts b/packages/client/lib/commands/index.ts index b95d7467a6..491e0b3224 100644 --- a/packages/client/lib/commands/index.ts +++ b/packages/client/lib/commands/index.ts @@ -145,6 +145,7 @@ import XACK from './XACK'; import XADD_NOMKSTREAM from './XADD_NOMKSTREAM'; import XADD from './XADD'; import XDEL from './XDEL'; +import XSETID from './XSETID'; import XTRIM from './XTRIM'; import XLEN from './XLEN'; import ZADD from './ZADD'; @@ -467,6 +468,8 @@ export default { xAdd: XADD, XDEL, xDel: XDEL, + XSETID, + xSetId: XSETID, XTRIM, xTrim: XTRIM, XLEN, diff --git a/todo.md b/todo.md index d3c2e81aa3..3be2364f5c 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,6 @@ -# return type +# return type \ missing documentation - `XAUTOCLAIM` +- `XSETID` # create commands