You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
ref #2489
This commit is contained in:
46
packages/client/lib/commands/ZRANK_WITHSCORE.spec.ts
Normal file
46
packages/client/lib/commands/ZRANK_WITHSCORE.spec.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ZRANK_WITHSCORE from './ZRANK_WITHSCORE';
|
||||
|
||||
describe('ZRANK WITHSCORE', () => {
|
||||
testUtils.isVersionGreaterThanHook([7, 2]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ZRANK_WITHSCORE.transformArguments('key', 'member'),
|
||||
['ZRANK', 'key', 'member', 'WITHSCORE']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testAll('zRankWithScore - null', async client => {
|
||||
assert.equal(
|
||||
await client.zRankWithScore('key', 'member'),
|
||||
null
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
|
||||
testUtils.testAll('zRankWithScore - with member', async client => {
|
||||
const member = {
|
||||
value: '1',
|
||||
score: 1
|
||||
}
|
||||
|
||||
const [, reply] = await Promise.all([
|
||||
client.zAdd('key', member),
|
||||
client.zRankWithScore('key', member.value)
|
||||
])
|
||||
assert.deepEqual(
|
||||
reply,
|
||||
{
|
||||
rank: 0,
|
||||
score: 1
|
||||
}
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
30
packages/client/lib/commands/ZRANK_WITHSCORE.ts
Normal file
30
packages/client/lib/commands/ZRANK_WITHSCORE.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { NullReply, TuplesReply, NumberReply, BlobStringReply, DoubleReply, Command } from '../RESP/types';
|
||||
import ZRANK from './ZRANK';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: ZRANK.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: ZRANK.IS_READ_ONLY,
|
||||
transformArguments(...args: Parameters<typeof ZRANK.transformArguments>) {
|
||||
const redisArgs = ZRANK.transformArguments(...args);
|
||||
redisArgs.push('WITHSCORE');
|
||||
return redisArgs;
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: NullReply | TuplesReply<[NumberReply, BlobStringReply]>) => {
|
||||
if (reply === null) return null;
|
||||
|
||||
return {
|
||||
rank: reply[0],
|
||||
score: Number(reply[1])
|
||||
};
|
||||
},
|
||||
3: (reply: NullReply | TuplesReply<[BlobStringReply, DoubleReply]>) => {
|
||||
if (reply === null) return null;
|
||||
|
||||
return {
|
||||
rank: reply[0],
|
||||
score: reply[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
} as const satisfies Command;
|
@@ -286,6 +286,7 @@ import ZRANGEBYSCORE_WITHSCORES from './ZRANGEBYSCORE_WITHSCORES';
|
||||
import ZRANGEBYSCORE from './ZRANGEBYSCORE';
|
||||
import ZRANGESTORE from './ZRANGESTORE';
|
||||
import ZREMRANGEBYSCORE from './ZREMRANGEBYSCORE';
|
||||
import ZRANK_WITHSCORE from './ZRANK_WITHSCORE';
|
||||
import ZRANK from './ZRANK';
|
||||
import ZREM from './ZREM';
|
||||
import ZREMRANGEBYLEX from './ZREMRANGEBYLEX';
|
||||
@@ -586,6 +587,7 @@ type ZRANGEBYSCORE_WITHSCORES = typeof import('./ZRANGEBYSCORE_WITHSCORES').defa
|
||||
type ZRANGEBYSCORE = typeof import('./ZRANGEBYSCORE').default;
|
||||
type ZRANGESTORE = typeof import('./ZRANGESTORE').default;
|
||||
type ZREMRANGEBYSCORE = typeof import('./ZREMRANGEBYSCORE').default;
|
||||
type ZRANK_WITHSCORE = typeof import('./ZRANK_WITHSCORE').default;
|
||||
type ZRANK = typeof import('./ZRANK').default;
|
||||
type ZREM = typeof import('./ZREM').default;
|
||||
type ZREMRANGEBYLEX = typeof import('./ZREMRANGEBYLEX').default;
|
||||
@@ -1174,6 +1176,8 @@ type Commands = {
|
||||
zRangeByScore: ZRANGEBYSCORE;
|
||||
ZRANGESTORE: ZRANGESTORE;
|
||||
zRangeStore: ZRANGESTORE;
|
||||
ZRANK_WITHSCORE: ZRANK_WITHSCORE;
|
||||
zRankWithScore: ZRANK_WITHSCORE;
|
||||
ZRANK: ZRANK;
|
||||
zRank: ZRANK;
|
||||
ZREM: ZREM;
|
||||
@@ -1775,6 +1779,8 @@ export default {
|
||||
zRangeByScore: ZRANGEBYSCORE,
|
||||
ZRANGESTORE,
|
||||
zRangeStore: ZRANGESTORE,
|
||||
ZRANK_WITHSCORE,
|
||||
zRankWithScore: ZRANK_WITHSCORE,
|
||||
ZRANK,
|
||||
zRank: ZRANK,
|
||||
ZREM,
|
||||
|
Reference in New Issue
Block a user