You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +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,38 +1,32 @@
|
||||
export function transformArguments(): Array<string> {
|
||||
import { ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, UnwrapReply, Resp2Reply, Command } from '../RESP/types';
|
||||
|
||||
type ClusterLinksReply = ArrayReply<TuplesToMapReply<[
|
||||
[BlobStringReply<'direction'>, BlobStringReply],
|
||||
[BlobStringReply<'node'>, BlobStringReply],
|
||||
[BlobStringReply<'create-time'>, NumberReply],
|
||||
[BlobStringReply<'events'>, BlobStringReply],
|
||||
[BlobStringReply<'send-buffer-allocated'>, NumberReply],
|
||||
[BlobStringReply<'send-buffer-used'>, NumberReply],
|
||||
]>>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLUSTER', 'LINKS'];
|
||||
}
|
||||
|
||||
type ClusterLinksRawReply = Array<[
|
||||
'direction',
|
||||
string,
|
||||
'node',
|
||||
string,
|
||||
'createTime',
|
||||
number,
|
||||
'events',
|
||||
string,
|
||||
'send-buffer-allocated',
|
||||
number,
|
||||
'send-buffer-used',
|
||||
number
|
||||
]>;
|
||||
|
||||
type ClusterLinksReply = Array<{
|
||||
direction: string;
|
||||
node: string;
|
||||
createTime: number;
|
||||
events: string;
|
||||
sendBufferAllocated: number;
|
||||
sendBufferUsed: number;
|
||||
}>;
|
||||
|
||||
export function transformReply(reply: ClusterLinksRawReply): ClusterLinksReply {
|
||||
return reply.map(peerLink => ({
|
||||
direction: peerLink[1],
|
||||
node: peerLink[3],
|
||||
createTime: Number(peerLink[5]),
|
||||
events: peerLink[7],
|
||||
sendBufferAllocated: Number(peerLink[9]),
|
||||
sendBufferUsed: Number(peerLink[11])
|
||||
}));
|
||||
}
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: UnwrapReply<Resp2Reply<ClusterLinksReply>>) => reply.map(link => {
|
||||
const unwrapped = link as unknown as UnwrapReply<typeof link>;
|
||||
return {
|
||||
direction: unwrapped[1],
|
||||
node: unwrapped[3],
|
||||
'create-time': unwrapped[5],
|
||||
events: unwrapped[7],
|
||||
'send-buffer-allocated': unwrapped[9],
|
||||
'send-buffer-used': unwrapped[11]
|
||||
};
|
||||
}),
|
||||
3: undefined as unknown as () => ClusterLinksReply
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user