Sending Commands to Multiple Nodes in an ioredis Cluster

Asked 1 years ago, Updated 1 years ago, 52 views

Ioredis would like to send commands to multiple nodes in the cluster (such as flushall and keys).

After reviewing the following documentation, I was going to use the node list that I got from Cluster#nodes, but when I called Cluster#nodes, it returned an empty array and I couldn't continue.
https://github.com/luin/ioredis/blob/master/README.md
Running commands to multiple nodes item

We are testing with the following source code to verify the node list.

var Redis=require('ioredis');

varcluster=newRedis.Cluster([{{
  host: '127.0.0.1',
  port —7000
}, {
  host: '127.0.0.1',
  port —7001
}, {
  host: '127.0.0.1',
  port —7002
}]);

console.log(cluster.nodes());

When I tried outputting the cluster, the nodes did not contain any values as shown below.

Cluster{
  domain —null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  slots: [ ],
  retryAttempts: 0,
  delayQueue:DelayQueue {queues:{},timeouts:{},
  offlineQueue: 
   US>Denque{
     _head —0,
     _tail —0,
     _capacityMask—3,
     _list: <4 empty items>},
  isRefreshing: false,
  connectionEpoch: 1,
  options: 
   { showFriendlyErrorStack: false,
     clusterRetryStratey: Function: clusterRetryStratey,
     enableOfflineQueue: true,
     enableReadyCheck: true,
     scaleReads: 'master',
     maxRedirections—16,
     retryDelayOnFailover: 100,
     retryDelayOnClusterDown: 100,
     retryDelayOnTryAgain: 100,
     slotsRefreshTimeout: 1000,
     slotsRefreshInterval: 5000,
     dnsLookup: Function:lookup},
  scriptsSet: {},
  startupNodes: 
   [{host:'127.0.0.1', port:7000},
     { host: '127.0.0.1', port:7001},
     { host: '127.0.0.1', port:7002} ,
  connectionPool: 
   ConnectionPool {
     domain —null,
     _events: 
      { '-node': Array,
        '+node': Array,
        drain —Function,
        nodeError: Function},
     _eventsCount—4,
     _maxListeners: undefined,
     redisOptions: undefined,
     nodes: {all:{}, master:{}, slave:{},
     specifiedOptions: {},
  subscriber: 
   ClusterSubscriber {
     connectionPool: 
      ConnectionPool {
        domain —null,
        _ events —Object,
        _eventsCount—4,
        _maxListeners: undefined,
        redisOptions: undefined,
        nodes —Object,
        specifiedOptions: {},
     emitter: Circular,
     started: false,
     subscriber:null},
  status: 'connecting'}

Please let me know if there is anything wrong or missing.

redis

2022-09-30 13:47

1 Answers

You can now retrieve node information with the following correspondence:

var Redis=require('ioredis');

varcluster=newRedis.Cluster([{{
  host: '127.0.0.1',
  port —7000
}, {
  host: '127.0.0.1',
  port —7001
}, {
  host: '127.0.0.1',
  port —7002
}]);

// console.log (cluster);

cluster.on('connect',()=>{
  console.log(cluster);
});


2022-09-30 13:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.