Skip to content

Commit 9a2efa6

Browse files
wait for cluster ready
1 parent a334833 commit 9a2efa6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

js/ioredis/lib/redisManager.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,26 @@ async function runBenchmark(argv) {
7373
}
7474
);
7575

76+
// Wait for cluster to be ready and discover all nodes
77+
await new Promise((resolve) => {
78+
cluster.on('ready', resolve);
79+
});
80+
81+
// Get all master nodes from the cluster
82+
const nodes = cluster.nodes('master');
83+
console.log(`Cluster mode - discovered ${nodes.length} master nodes`);
7684

85+
// Populate slotClientMap by using the cluster client for all slots
86+
// The cluster client will automatically route commands to the correct node
87+
// based on the key's hash slot, handling MOVED/ASK redirects automatically
88+
for (let slot = 0; slot <= 16383; slot++) {
89+
slotClientMap.set(slot, cluster);
90+
}
7791

7892
clients.push(cluster);
79-
80-
console.log(`Cluster mode - using ${nodeAddresses.length} unique nodes`);
93+
nodeAddresses = nodes.map(node => `${node.options.host}:${node.options.port}`);
94+
95+
console.log(`Cluster mode - using ${nodeAddresses.length} unique nodes: ${nodeAddresses.join(', ')}`);
8196
} else {
8297
const client = new Redis(redisOptions);
8398
clients.push(client);

0 commit comments

Comments
 (0)