Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/client/lib/commands/ZREVRANK_WITHSCORE.spec.ts
Original file line number Diff line number Diff line change
@@ -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
});
});
15 changes: 15 additions & 0 deletions packages/client/lib/commands/ZREVRANK_WITHSCORE.ts
Original file line number Diff line number Diff line change
@@ -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<typeof ZREVRANK.parseCommand>) {
const parser = args[0];

ZREVRANK.parseCommand(...args);
parser.push('WITHSCORE');
},
transformReply: ZRANK_WITHSCORE.transformReply
} as const satisfies Command;
11 changes: 11 additions & 0 deletions packages/client/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down