Skip to content

Support ZRANK and ZREVRANK: Added the optional WITHSCORE argument #2489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions packages/client/lib/cluster/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ import * as ZRANGEBYSCORE_WITHSCORES from '../commands/ZRANGEBYSCORE_WITHSCORES'
import * as ZRANGEBYSCORE from '../commands/ZRANGEBYSCORE';
import * as ZRANGESTORE from '../commands/ZRANGESTORE';
import * as ZRANK from '../commands/ZRANK';
import * as ZRANK_WITHSCORE from '../commands/ZRANK_WITHSCORE';
import * as ZREM from '../commands/ZREM';
import * as ZREMRANGEBYLEX from '../commands/ZREMRANGEBYLEX';
import * as ZREMRANGEBYRANK from '../commands/ZREMRANGEBYRANK';
import * as ZREMRANGEBYSCORE from '../commands/ZREMRANGEBYSCORE';
import * as ZREVRANK from '../commands/ZREVRANK';
import * as ZREVRANK_WITHSCORE from '../commands/ZREVRANK_WITHSCORE';
import * as ZSCAN from '../commands/ZSCAN';
import * as ZSCORE from '../commands/ZSCORE';
import * as ZUNION_WITHSCORES from '../commands/ZUNION_WITHSCORES';
Expand Down Expand Up @@ -614,6 +616,8 @@ export default {
zRangeStore: ZRANGESTORE,
ZRANK,
zRank: ZRANK,
ZRANK_WITHSCORE,
zRankWithScore: ZRANK_WITHSCORE,
ZREM,
zRem: ZREM,
ZREMRANGEBYLEX,
Expand All @@ -624,6 +628,8 @@ export default {
zRemRangeByScore: ZREMRANGEBYSCORE,
ZREVRANK,
zRevRank: ZREVRANK,
ZREVRANK_WITHSCORE,
zRevRankWithScore: ZREVRANK_WITHSCORE,
ZSCAN,
zScan: ZSCAN,
ZSCORE,
Expand Down
49 changes: 49 additions & 0 deletions packages/client/lib/commands/ZRANK_WITHSCORE.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './ZRANK_WITHSCORE';

describe('ZRANK WITHSCORE', () => {
testUtils.isVersionGreaterThanHook([7, 2]);

it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'member'),
['ZRANK', 'key', 'member', 'WITHSCORE']
);
});

it('transformReply', () => {
assert.deepEqual(
transformReply([]),
null
);
assert.deepEqual(
transformReply(['test', '1']),
{
value: 'test',
score: 1
}
);
});

testUtils.testWithClient('client.zRankWithScore empty response', async client => {
assert.deepEqual(
await client.zRankWithScore('key', 'member'),
null
);
}, GLOBAL.SERVERS.OPEN);

testUtils.testWithClient('client.zRankWithScore', async client => {
await Promise.all([
client.zAdd('zRankWithScoreSet', 1, 'one'),
client.zAdd('zRankWithScoreSet', 2, 'two')
]);
assert.deepEqual(
await client.zRankWithScore('zRankWithScoreSet', 'one'),
{
value: 'one',
score: 0
}
);
}, GLOBAL.SERVERS.OPEN);
});
13 changes: 13 additions & 0 deletions packages/client/lib/commands/ZRANK_WITHSCORE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { RedisCommandArguments } from '.';
import { transformArguments as transformZRankArguments } from './ZRANK';

export { FIRST_KEY_INDEX, IS_READ_ONLY } from './ZRANK';

export function transformArguments(...args: Parameters<typeof transformZRankArguments>): RedisCommandArguments {
return [
...transformZRankArguments(...args),
'WITHSCORE'
];
}

export { transformSortedSetMemberNullReply as transformReply } from './generic-transformers';
49 changes: 49 additions & 0 deletions packages/client/lib/commands/ZREVRANK_WITHSCORE.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './ZREVRANK_WITHSCORE';

describe('ZREVRANK WITHSCORE', () => {
testUtils.isVersionGreaterThanHook([7, 2]);

it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'member'),
['ZREVRANK', 'key', 'member', 'WITHSCORE']
);
});

it('transformReply', () => {
assert.deepEqual(
transformReply([]),
null
);
assert.deepEqual(
transformReply(['test', '1']),
{
value: 'test',
score: 1
}
);
});

testUtils.testWithClient('client.zRevRankWithScore empty response', async client => {
assert.deepEqual(
await client.zRevRankWithScore('key', 'member'),
null
);
}, GLOBAL.SERVERS.OPEN);

testUtils.testWithClient('client.zRevRankWithScore', async client => {
await Promise.all([
client.zAdd('zRevRankWithScoreSet', 1, 'one'),
client.zAdd('zRevRankWithScoreSet', 2, 'two')
]);
assert.deepEqual(
await client.zRevRankWithScore('zRevRankWithScoreSet', 'one'),
{
value: 'one',
score: 1
}
);
}, GLOBAL.SERVERS.OPEN);
});
13 changes: 13 additions & 0 deletions packages/client/lib/commands/ZREVRANK_WITHSCORE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { RedisCommandArguments } from '.';
import { transformArguments as transformZRevRankArguments } from './ZREVRANK';

export { FIRST_KEY_INDEX, IS_READ_ONLY } from './ZREVRANK';

export function transformArguments(...args: Parameters<typeof transformZRevRankArguments>): RedisCommandArguments {
return [
...transformZRevRankArguments(...args),
'WITHSCORE'
];
}

export { transformSortedSetMemberNullReply as transformReply } from './generic-transformers';