From 21934d44d7b138da1a0c3851db8d4469a1a779e3 Mon Sep 17 00:00:00 2001 From: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com> Date: Sun, 17 May 2026 11:55:37 +0530 Subject: [PATCH] feat(client): add zrevrank withscore command --- .../lib/commands/ZREVRANK_WITHSCORE.spec.ts | 50 +++++++++++++++++++ .../client/lib/commands/ZREVRANK_WITHSCORE.ts | 15 ++++++ packages/client/lib/commands/index.ts | 11 ++++ 3 files changed, 76 insertions(+) create mode 100644 packages/client/lib/commands/ZREVRANK_WITHSCORE.spec.ts create mode 100644 packages/client/lib/commands/ZREVRANK_WITHSCORE.ts diff --git a/packages/client/lib/commands/ZREVRANK_WITHSCORE.spec.ts b/packages/client/lib/commands/ZREVRANK_WITHSCORE.spec.ts new file mode 100644 index 0000000000..a0a476852f --- /dev/null +++ b/packages/client/lib/commands/ZREVRANK_WITHSCORE.spec.ts @@ -0,0 +1,50 @@ +import { strict as assert } from 'node:assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { parseArgs } from './generic-transformers'; +import ZREVRANK_WITHSCORE from './ZREVRANK_WITHSCORE'; + +describe('ZREVRANK WITHSCORE', () => { + testUtils.isVersionGreaterThanHook([7, 2]); + + it('transformArguments', () => { + assert.deepEqual( + parseArgs(ZREVRANK_WITHSCORE, 'key', 'member'), + ['ZREVRANK', 'key', 'member', 'WITHSCORE'] + ); + }); + + testUtils.testAll('zRevRankWithScore - null', async client => { + assert.equal( + await client.zRevRankWithScore('key', 'member'), + null + ); + }, { + client: GLOBAL.SERVERS.OPEN, + cluster: GLOBAL.CLUSTERS.OPEN + }); + + testUtils.testAll('zRevRankWithScore - with member', async client => { + const members = [{ + value: '1', + score: 1 + }, { + value: '2', + score: 2 + }]; + + const [, reply] = await Promise.all([ + client.zAdd('key', members), + client.zRevRankWithScore('key', members[0].value) + ]); + assert.deepEqual( + reply, + { + rank: 1, + score: 1 + } + ); + }, { + client: GLOBAL.SERVERS.OPEN, + cluster: GLOBAL.CLUSTERS.OPEN + }); +}); diff --git a/packages/client/lib/commands/ZREVRANK_WITHSCORE.ts b/packages/client/lib/commands/ZREVRANK_WITHSCORE.ts new file mode 100644 index 0000000000..8a1701b5cc --- /dev/null +++ b/packages/client/lib/commands/ZREVRANK_WITHSCORE.ts @@ -0,0 +1,15 @@ +import ZRANK_WITHSCORE from './ZRANK_WITHSCORE'; +import ZREVRANK from './ZREVRANK'; +import { Command } from '../RESP/types'; + +export default { + CACHEABLE: ZREVRANK.CACHEABLE, + IS_READ_ONLY: ZREVRANK.IS_READ_ONLY, + parseCommand(...args: Parameters) { + const parser = args[0]; + + ZREVRANK.parseCommand(...args); + parser.push('WITHSCORE'); + }, + transformReply: ZRANK_WITHSCORE.transformReply +} as const satisfies Command; diff --git a/packages/client/lib/commands/index.ts b/packages/client/lib/commands/index.ts index 0c60cb58d5..437eb83166 100644 --- a/packages/client/lib/commands/index.ts +++ b/packages/client/lib/commands/index.ts @@ -352,6 +352,7 @@ import ZRANK from './ZRANK'; import ZREM from './ZREM'; import ZREMRANGEBYLEX from './ZREMRANGEBYLEX'; import ZREMRANGEBYRANK from './ZREMRANGEBYRANK'; +import ZREVRANK_WITHSCORE from './ZREVRANK_WITHSCORE'; import ZREVRANK from './ZREVRANK'; import ZSCAN from './ZSCAN'; import ZSCORE from './ZSCORE'; @@ -5303,6 +5304,16 @@ export default { * @param max - Maximum score. */ zRemRangeByScore: ZREMRANGEBYSCORE, + /** + * Returns the reverse rank of a member in the sorted set with its score. + * @param args - Same parameters as the ZREVRANK command. + */ + ZREVRANK_WITHSCORE, + /** + * Returns the reverse rank of a member in the sorted set with its score. + * @param args - Same parameters as the ZREVRANK command. + */ + zRevRankWithScore: ZREVRANK_WITHSCORE, /** * Returns the rank of a member in the sorted set, with scores ordered from high to low. * @param key - Key of the sorted set.