1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Support SORT_RO (#2041)

* Support SORT_RO

* move pushSortReadOnlyArgs and SortReadOnlyOptions to generic-transformers

* clean code

Co-authored-by: leibale <leibale1998@gmail.com>
This commit is contained in:
Avital Fine
2022-03-29 00:36:47 +02:00
committed by GitHub
parent 5821fcbe4d
commit f6f645bdbb
8 changed files with 288 additions and 65 deletions

View File

@@ -438,6 +438,50 @@ export function transformCommandReply(
};
}
export interface SortOptions {
BY?: string;
LIMIT?: {
offset: number;
count: number;
},
GET?: string | Array<string>;
DIRECTION?: 'ASC' | 'DESC';
ALPHA?: true;
}
export function pushSortArguments(
args: RedisCommandArguments,
options?: SortOptions
): RedisCommandArguments {
if (options?.BY) {
args.push('BY', options.BY);
}
if (options?.LIMIT) {
args.push(
'LIMIT',
options.LIMIT.offset.toString(),
options.LIMIT.count.toString()
);
}
if (options?.GET) {
for (const pattern of (typeof options.GET === 'string' ? [options.GET] : options.GET)) {
args.push('GET', pattern);
}
}
if (options?.DIRECTION) {
args.push(options.DIRECTION);
}
if (options?.ALPHA) {
args.push('ALPHA');
}
return args;
}
export interface SlotRange {
start: number;
end: number;