1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/packages/client/lib/commands/ZRANGESTORE.ts

62 lines
1.3 KiB
TypeScript

import { transformArgumentStringNumberInfinity } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
interface ZRangeStoreOptions {
BY?: 'SCORE' | 'LEX';
REV?: true;
LIMIT?: {
offset: number;
count: number;
};
WITHSCORES?: true;
}
export function transformArguments(
dst: string,
src: string,
min: string | number,
max: string | number,
options?: ZRangeStoreOptions
): Array<string> {
const args = [
'ZRANGESTORE',
dst,
src,
transformArgumentStringNumberInfinity(min),
transformArgumentStringNumberInfinity(max)
];
switch (options?.BY) {
case 'SCORE':
args.push('BYSCORE');
break;
case 'LEX':
args.push('BYLEX');
break;
}
if (options?.REV) {
args.push('REV');
}
if (options?.LIMIT) {
args.push('LIMIT', options.LIMIT.offset.toString(), options.LIMIT.count.toString());
}
if (options?.WITHSCORES) {
args.push('WITHSCORES');
}
return args;
}
export function transformReply(reply: number): number {
if (typeof reply !== 'number') {
throw new TypeError(`Upgrade to Redis 6.2.5 and up (https://github.com/redis/redis/pull/9089)`);
}
return reply;
}