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,26 +1,38 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { transformArguments as transformFunctionListArguments } from './FUNCTION_LIST';
|
||||
import { FunctionListItemReply, FunctionListRawItemReply, transformFunctionListItemReply } from './generic-transformers';
|
||||
import { TuplesToMapReply, BlobStringReply, ArrayReply, UnwrapReply, Resp2Reply, Command } from '../RESP/types';
|
||||
import FUNCTION_LIST, { FunctionListReplyItem } from './FUNCTION_LIST';
|
||||
|
||||
export function transformArguments(pattern?: string): RedisCommandArguments {
|
||||
const args = transformFunctionListArguments(pattern);
|
||||
args.push('WITHCODE');
|
||||
return args;
|
||||
}
|
||||
export type FunctionListWithCodeReply = ArrayReply<TuplesToMapReply<[
|
||||
...FunctionListReplyItem,
|
||||
[BlobStringReply<'library_code'>, BlobStringReply],
|
||||
]>>;
|
||||
|
||||
type FunctionListWithCodeRawItemReply = [
|
||||
...FunctionListRawItemReply,
|
||||
'library_code',
|
||||
string
|
||||
];
|
||||
|
||||
interface FunctionListWithCodeItemReply extends FunctionListItemReply {
|
||||
libraryCode: string;
|
||||
}
|
||||
|
||||
export function transformReply(reply: Array<FunctionListWithCodeRawItemReply>): Array<FunctionListWithCodeItemReply> {
|
||||
return reply.map(library => ({
|
||||
...transformFunctionListItemReply(library as unknown as FunctionListRawItemReply),
|
||||
libraryCode: library[7]
|
||||
}));
|
||||
}
|
||||
export default {
|
||||
FIRST_KEY_INDEX: FUNCTION_LIST.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: FUNCTION_LIST.IS_READ_ONLY,
|
||||
transformArguments(...args: Parameters<typeof FUNCTION_LIST.transformArguments>) {
|
||||
const redisArgs = FUNCTION_LIST.transformArguments(...args);
|
||||
redisArgs.push('WITHCODE');
|
||||
return redisArgs;
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: UnwrapReply<Resp2Reply<FunctionListWithCodeReply>>) => {
|
||||
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]
|
||||
};
|
||||
}),
|
||||
library_code: unwrapped[7]
|
||||
};
|
||||
});
|
||||
},
|
||||
3: undefined as unknown as () => FunctionListWithCodeReply
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user