redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cluster nodes is empty on elasticache

madhur opened this issue · comments

I am having a wierd issue, which I am unable to figure out. Basically, I am trying to flush the redis elasticache on aws running Redis 7.0.7.

Using node v14 with ioredis 5.3.2

Here is the simple code:

const Redis = require('ioredis');

// Replace these with your own ElastiCache endpoint and port
const clusterEndpoint = 'hostname';
const clusterPort = 6379;

// Initialize a new Redis cluster instance
const cluster = new Redis.Cluster(
  [
    { host: clusterEndpoint, port: clusterPort },
    // Add more nodes here if you have additional nodes in your cluster
    // { host: 'node2.example.cache.amazonaws.com', port: 6379 },
  ],
);

// Function to flush all keys in the cluster nodes

function flushAllKeysInCluster() {
    const nodes = cluster.nodes();
    console.log(nodes);
   let promise = Promise.all(nodes.map(function (node) {
  	return node.flushdb('async');
   }));
   return promise;
}

// Call the flushAllKeysInCluster function
flushAllKeysInCluster()
  .then(() => {
    console.log('All nodes flushed successfully.');
  })
  .catch((err) => {
    console.error(`Error flushing keys in the cluster: ${err.message}`);
  });

The issue is that console.log(nodes) prints the empty array [] .

I am able to connect the elasticache using redis-cli. Here is the debug output:

DEBUG=ioredis:* node rediscleanup.js 
  ioredis:cluster status: [empty] -> connecting +0ms
[]
All nodes flushed successfully.
  ioredis:cluster resolved hostname ****.amazonaws.com to IP 10.24.221.92 +25ms
  ioredis:cluster:connectionPool Reset with [ { host: '10.24.221.92', port: 6379 } ] +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.221.92:6379 as master +6ms
  ioredis:redis status[10.24.221.92:6379]: wait -> wait +0ms
  ioredis:cluster getting slot cache from 10.24.221.92:6379 +8ms
  ioredis:redis status[10.24.221.92:6379 (ioredis-cluster(refresher))]: wait -> wait +2ms
  ioredis:redis status[10.24.221.92:6379 (ioredis-cluster(refresher))]: wait -> connecting +5ms
  ioredis:redis queue command[10.24.221.92:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +0ms
  ioredis:cluster:subscriber selected a subscriber 10.24.221.92:6379 +0ms
  ioredis:redis status[10.24.221.92:6379 (ioredis-cluster(subscriber))]: wait -> wait +1ms
  ioredis:cluster:subscriber started +1ms
  ioredis:redis status[10.24.221.92:6379 (ioredis-cluster(refresher))]: connecting -> connect +7ms
  ioredis:redis status[10.24.221.92:6379 (ioredis-cluster(refresher))]: connect -> ready +1ms
  ioredis:connection set the connection name [ioredis-cluster(refresher)] +0ms
  ioredis:redis write command[10.24.221.92:6379 (ioredis-cluster(refresher))]: 0 -> client([ 'setname', 'ioredis-cluster(refresher)' ]) +0ms
  ioredis:connection send 1 commands in offline queue +4ms
  ioredis:redis write command[10.24.221.92:6379 (ioredis-cluster(refresher))]: 0 -> cluster([ 'SLOTS' ]) +4ms
  ioredis:cluster cluster slots result count: 10 +24ms
  ioredis:cluster cluster slots result [0]: slots 0~1638 served by [ '10.24.222.56:6379', '10.24.223.149:6379' ] +0ms
  ioredis:cluster cluster slots result [1]: slots 1639~3277 served by [ '10.24.221.92:6379', '10.24.223.242:6379' ] +1ms
  ioredis:cluster cluster slots result [2]: slots 3278~4916 served by [ '10.24.223.133:6379', '10.24.220.220:6379' ] +0ms
  ioredis:cluster cluster slots result [3]: slots 4917~6555 served by [ '10.24.221.19:6379', '10.24.222.85:6379' ] +0ms
  ioredis:cluster cluster slots result [4]: slots 6556~8193 served by [ '10.24.220.94:6379', '10.24.223.181:6379' ] +0ms
  ioredis:cluster cluster slots result [5]: slots 8194~9831 served by [ '10.24.222.137:6379', '10.24.221.229:6379' ] +1ms
  ioredis:cluster cluster slots result [6]: slots 9832~11469 served by [ '10.24.220.206:6379', '10.24.222.3:6379' ] +0ms
  ioredis:cluster cluster slots result [7]: slots 11470~13107 served by [ '10.24.221.53:6379', '10.24.220.108:6379' ] +1ms
  ioredis:cluster cluster slots result [8]: slots 13108~14745 served by [ '10.24.221.239:6379', '10.24.222.48:6379' ] +1ms
  ioredis:cluster cluster slots result [9]: slots 14746~16383 served by [ '10.24.222.122:6379', '10.24.220.166:6379' ] +0ms
  ioredis:cluster:connectionPool Reset with '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object  ... <REDACTED full-length="319">' +51ms
  ioredis:cluster:connectionPool Connecting to 10.24.222.56:6379 as master +1ms
  ioredis:redis status[10.24.222.56:6379]: wait -> wait +30ms
  ioredis:cluster:connectionPool Connecting to 10.24.223.149:6379 as slave +0ms
  ioredis:redis status[10.24.223.149:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.223.242:6379 as slave +0ms
  ioredis:redis status[10.24.223.242:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.223.133:6379 as master +1ms
  ioredis:redis status[10.24.223.133:6379]: wait -> wait +1ms
  ioredis:cluster:connectionPool Connecting to 10.24.220.220:6379 as slave +0ms
  ioredis:redis status[10.24.220.220:6379]: wait -> wait +2ms
  ioredis:cluster:connectionPool Connecting to 10.24.221.19:6379 as master +3ms
  ioredis:redis status[10.24.221.19:6379]: wait -> wait +2ms
  ioredis:cluster:connectionPool Connecting to 10.24.222.85:6379 as slave +1ms
  ioredis:redis status[10.24.222.85:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.220.94:6379 as master +0ms
  ioredis:redis status[10.24.220.94:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.223.181:6379 as slave +0ms
  ioredis:redis status[10.24.223.181:6379]: wait -> wait +1ms
  ioredis:cluster:connectionPool Connecting to 10.24.222.137:6379 as master +1ms
  ioredis:redis status[10.24.222.137:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.221.229:6379 as slave +0ms
  ioredis:redis status[10.24.221.229:6379]: wait -> wait +1ms
  ioredis:cluster:connectionPool Connecting to 10.24.220.206:6379 as master +1ms
  ioredis:redis status[10.24.220.206:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.222.3:6379 as slave +0ms
  ioredis:redis status[10.24.222.3:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.221.53:6379 as master +1ms
  ioredis:redis status[10.24.221.53:6379]: wait -> wait +1ms
  ioredis:cluster:connectionPool Connecting to 10.24.220.108:6379 as slave +0ms
  ioredis:redis status[10.24.220.108:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.221.239:6379 as master +0ms
  ioredis:redis status[10.24.221.239:6379]: wait -> wait +1ms
  ioredis:cluster:connectionPool Connecting to 10.24.222.48:6379 as slave +1ms
  ioredis:redis status[10.24.222.48:6379]: wait -> wait +1ms
  ioredis:cluster:connectionPool Connecting to 10.24.222.122:6379 as master +1ms
  ioredis:redis status[10.24.222.122:6379]: wait -> wait +0ms
  ioredis:cluster:connectionPool Connecting to 10.24.220.166:6379 as slave +0ms
  ioredis:redis status[10.24.220.166:6379]: wait -> wait +0ms
  ioredis:cluster status: connecting -> connect +32ms
  ioredis:redis status[10.24.223.133:6379]: wait -> connecting +10ms
  ioredis:redis queue command[10.24.223.133:6379]: 0 -> cluster([ 'INFO' ]) +0ms
  ioredis:redis status[10.24.223.133:6379]: connecting -> connect +1ms
  ioredis:redis write command[10.24.223.133:6379]: 0 -> info([]) +0ms
  ioredis:redis status[10.24.221.92:6379 (ioredis-cluster(refresher))]: ready -> close +3ms
  ioredis:connection skip reconnecting since the connection is manually closed. +58ms
  ioredis:redis status[10.24.221.92:6379 (ioredis-cluster(refresher))]: close -> end +4ms
  ioredis:redis status[10.24.223.133:6379]: connect -> ready +4ms
  ioredis:connection send 1 commands in offline queue +4ms
  ioredis:redis write command[10.24.223.133:6379]: 0 -> cluster([ 'INFO' ]) +0ms
  ioredis:cluster status: connect -> ready +24ms