File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments