You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
V5 bringing RESP3, Sentinel and TypeMapping to node-redis
RESP3 Support - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion. Sentinel TypeMapping Correctly types Multi commands Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
@@ -1,44 +1,47 @@
|
||||
import {
|
||||
AggregateOptions,
|
||||
AggregateRawReply,
|
||||
AggregateReply,
|
||||
transformArguments as transformAggregateArguments,
|
||||
transformReply as transformAggregateReply
|
||||
} from './AGGREGATE';
|
||||
import { RedisArgument, Command, ReplyUnion, NumberReply } from '@redis/client/dist/lib/RESP/types';
|
||||
import AGGREGATE, { AggregateRawReply, AggregateReply, FtAggregateOptions } from './AGGREGATE';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './AGGREGATE';
|
||||
|
||||
interface AggregateWithCursorOptions extends AggregateOptions {
|
||||
COUNT?: number;
|
||||
export interface FtAggregateWithCursorOptions extends FtAggregateOptions {
|
||||
COUNT?: number;
|
||||
MAXIDLE?: number;
|
||||
}
|
||||
|
||||
export function transformArguments(
|
||||
index: string,
|
||||
query: string,
|
||||
options?: AggregateWithCursorOptions
|
||||
) {
|
||||
const args = transformAggregateArguments(index, query, options);
|
||||
|
||||
type AggregateWithCursorRawReply = [
|
||||
result: AggregateRawReply,
|
||||
cursor: NumberReply
|
||||
];
|
||||
|
||||
export interface AggregateWithCursorReply extends AggregateReply {
|
||||
cursor: NumberReply;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: AGGREGATE.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: AGGREGATE.IS_READ_ONLY,
|
||||
transformArguments(index: RedisArgument, query: RedisArgument, options?: FtAggregateWithCursorOptions) {
|
||||
const args = AGGREGATE.transformArguments(index, query, options);
|
||||
args.push('WITHCURSOR');
|
||||
if (options?.COUNT) {
|
||||
args.push('COUNT', options.COUNT.toString());
|
||||
|
||||
if (options?.COUNT !== undefined) {
|
||||
args.push('COUNT', options.COUNT.toString());
|
||||
}
|
||||
|
||||
if(options?.MAXIDLE !== undefined) {
|
||||
args.push('MAXIDLE', options.MAXIDLE.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]),
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: AggregateWithCursorRawReply): AggregateWithCursorReply => {
|
||||
return {
|
||||
...AGGREGATE.transformReply[2](reply[0]),
|
||||
cursor: reply[1]
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
3: undefined as unknown as () => ReplyUnion
|
||||
},
|
||||
unstableResp3: true
|
||||
} as const satisfies Command;
|
||||
|
||||
|
Reference in New Issue
Block a user