You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +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,34 +1,48 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { ScanOptions, pushScanArguments } from './generic-transformers';
|
||||
import { RedisArgument, CommandArguments, BlobStringReply, ArrayReply, Command } from '../RESP/types';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
export interface ScanCommandOptions extends ScanOptions {
|
||||
TYPE?: RedisCommandArgument;
|
||||
export interface ScanCommonOptions {
|
||||
MATCH?: string;
|
||||
COUNT?: number;
|
||||
}
|
||||
|
||||
export function transformArguments(
|
||||
cursor: number,
|
||||
options?: ScanCommandOptions
|
||||
): RedisCommandArguments {
|
||||
export function pushScanArguments(
|
||||
args: CommandArguments,
|
||||
cursor: RedisArgument,
|
||||
options?: ScanOptions
|
||||
): CommandArguments {
|
||||
args.push(cursor.toString());
|
||||
|
||||
if (options?.MATCH) {
|
||||
args.push('MATCH', options.MATCH);
|
||||
}
|
||||
|
||||
if (options?.COUNT) {
|
||||
args.push('COUNT', options.COUNT.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export interface ScanOptions extends ScanCommonOptions {
|
||||
TYPE?: RedisArgument;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(cursor: RedisArgument, options?: ScanOptions) {
|
||||
const args = pushScanArguments(['SCAN'], cursor, options);
|
||||
|
||||
if (options?.TYPE) {
|
||||
args.push('TYPE', options.TYPE);
|
||||
args.push('TYPE', options.TYPE);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
type ScanRawReply = [string, Array<string>];
|
||||
|
||||
export interface ScanReply {
|
||||
cursor: number;
|
||||
keys: Array<RedisCommandArgument>;
|
||||
}
|
||||
|
||||
export function transformReply([cursor, keys]: ScanRawReply): ScanReply {
|
||||
},
|
||||
transformReply([cursor, keys]: [BlobStringReply, ArrayReply<BlobStringReply>]) {
|
||||
return {
|
||||
cursor: Number(cursor),
|
||||
keys
|
||||
cursor,
|
||||
keys
|
||||
};
|
||||
}
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user