1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

close #2166 - add support for cursor api (#2217)

This commit is contained in:
Leibale Eidelman
2022-08-15 08:40:03 -04:00
committed by GitHub
parent 7b7d0d2a36
commit 1fdee05dd2
8 changed files with 196 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import {
AggregateOptions,
AggregateRawReply,
AggregateReply,
transformArguments as transformAggregateArguments,
transformReply as transformAggregateReply
} from './AGGREGATE';
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './AGGREGATE';
interface AggregateWithCursorOptions extends AggregateOptions {
COUNT?: number;
}
export function transformArguments(
index: string,
query: string,
options?: AggregateWithCursorOptions
) {
const args = transformAggregateArguments(index, query, options);
args.push('WITHCURSOR');
if (options?.COUNT) {
args.push('COUNT', options.COUNT.toString());
}
return args;
}
type AggregateWithCursorRawReply = [
result: AggregateRawReply,
cursor: number
];
interface AggregateWithCursorReply extends AggregateReply {
cursor: number;
}
export function transformReply(reply: AggregateWithCursorRawReply): AggregateWithCursorReply {
return {
...transformAggregateReply(reply[0]),
cursor: reply[1]
};
}