You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
40 lines
830 B
TypeScript
40 lines
830 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 {
|
|
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
|
|
};
|
|
}
|