1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/packages/client/lib/commands/CLUSTER_SLOTS.ts
Leibale 331e390bef WIP
2023-05-03 17:29:36 -04:00

41 lines
860 B
TypeScript

import { NumberReply, ArrayReply, BlobStringReply, Command } from '../RESP/types';
type RawNode = [
host: BlobStringReply,
port: NumberReply,
id: BlobStringReply
];
type ClusterSlotsRawReply = ArrayReply<[
from: NumberReply,
to: NumberReply,
master: RawNode,
...replicas: Array<RawNode>
]>;
export type ClusterSlotsNode = ReturnType<typeof transformNode>;
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments() {
return ['CLUSTER', 'SLOTS'];
},
transformReply(reply: ClusterSlotsRawReply) {
return reply.map(([from, to, master, ...replicas]) => ({
from,
to,
master: transformNode(master),
replicas: replicas.map(transformNode)
}));
}
} as const satisfies Command;
function transformNode([host, port, id ]: RawNode) {
return {
host,
port,
id
};
}