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,16 +1,51 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { FunctionListItemReply, FunctionListRawItemReply, transformFunctionListItemReply } from './generic-transformers';
|
||||
import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, NullReply, SetReply, UnwrapReply, Resp2Reply, CommandArguments, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(pattern?: string): RedisCommandArguments {
|
||||
const args = ['FUNCTION', 'LIST'];
|
||||
export interface FunctionListOptions {
|
||||
LIBRARYNAME?: RedisArgument;
|
||||
}
|
||||
|
||||
if (pattern) {
|
||||
args.push(pattern);
|
||||
export type FunctionListReplyItem = [
|
||||
[BlobStringReply<'library_name'>, BlobStringReply | NullReply],
|
||||
[BlobStringReply<'engine'>, BlobStringReply],
|
||||
[BlobStringReply<'functions'>, ArrayReply<TuplesToMapReply<[
|
||||
[BlobStringReply<'name'>, BlobStringReply],
|
||||
[BlobStringReply<'description'>, BlobStringReply | NullReply],
|
||||
[BlobStringReply<'flags'>, SetReply<BlobStringReply>],
|
||||
]>>]
|
||||
];
|
||||
|
||||
export type FunctionListReply = ArrayReply<TuplesToMapReply<FunctionListReplyItem>>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(options?: FunctionListOptions) {
|
||||
const args: CommandArguments = ['FUNCTION', 'LIST'];
|
||||
|
||||
if (options?.LIBRARYNAME) {
|
||||
args.push('LIBRARYNAME', options.LIBRARYNAME);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export function transformReply(reply: Array<FunctionListRawItemReply>): Array<FunctionListItemReply> {
|
||||
return reply.map(transformFunctionListItemReply);
|
||||
}
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: UnwrapReply<Resp2Reply<FunctionListReply>>) => {
|
||||
return reply.map(library => {
|
||||
const unwrapped = library as unknown as UnwrapReply<typeof library>;
|
||||
return {
|
||||
library_name: unwrapped[1],
|
||||
engine: unwrapped[3],
|
||||
functions: (unwrapped[5] as unknown as UnwrapReply<typeof unwrapped[5]>).map(fn => {
|
||||
const unwrapped = fn as unknown as UnwrapReply<typeof fn>;
|
||||
return {
|
||||
name: unwrapped[1],
|
||||
description: unwrapped[3],
|
||||
flags: unwrapped[5]
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
},
|
||||
3: undefined as unknown as () => FunctionListReply
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user