ioredis: ClusterAllFailedError: Failed to refresh slots cache.

Hi All. i have following error can You help me ? [ioredis] Unhandled error event: ClusterAllFailedError: Failed to refresh slots cache.

code is following. `“use strict”; require(‘./config/config’); const Redis = require(‘ioredis’);

(async()=> {

const startupNodes = [
    {host: process.env.REDIS_HOST_1, port: process.env.REDIS_PORT },
    {host: process.env.REDIS_HOST_2, port: process.env.REDIS_PORT}
    ];
const options = {
    slotsRefreshTimeout: 2000,
    dnsLookup: (address, callback) => callback(null, address),
    redisOptions: {
        tls: {},
        password: process.env.REDIS_PASS,
    },
};
const cluster = new Redis.Cluster(startupNodes, options);
console.log(cluster);

})();`

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 6
  • Comments: 23

Most upvoted comments

Same issue here

Have the same issue. Using an AWS elasticache redis (cluster mode enabled with multiple shards). I get the issue when using in-transit encryption and trying to access behind a NAT instance.

The only fix that seems to work for me is to up the slotsRefreshTimeout… 😕

I wander why the default timeout value is so “dangerously” low. The response to the slots commands just seems to sometimes take 2 or 3 seconds for me. Too bad then that by the time the slots “response” comes the client has already given up…

I suggest setting DEBUG="ioredis:*" and see if anything turns up. I wonder if it’s still trying to do AUTH.

Hi, I have the same issue using AWS ElastiCache & ioredis:

[ElastiCache] Configuration Endpoint: clustercfg.test1.xxxxxx.use2.cache.amazonaws.com:6379 Engine Version Compatibility: 5.0.6 Parameter Group: default.redis5.0.cluster.on (in-sync) Engine:Engine: Clustered Redis Encryption in-transit: Yes Encryption at-rest: No

[ioredis] version: 4.17.3

new Cluster([
  {"port":6379,"host":"clustercfg.test1.xxxxxx.use2.cache.amazonaws.com"}
], {
    dnsLookup: (address, callback) => {
            console.log('====[dnsLookup]====');
            return callback(null, address);
    },
    redisOptions: {
            tls: {},
    },
})

Error: ClusterAllFailedError: Failed to refresh slots cache.

What am I missing ?

We’re having a similar issue. Redis version: 5.0.4 on AWS ElasticCache Clustered (3 nodes, 1 shard) ioredis version: 4.16.0

Code to connect:

const Redis = require("ioredis");
var cluster = new Redis.Cluster([
  {
    host: <PRIMARY_RW_ENDPOINT>, port: 6379
  },
  {
   host: <SECONDARY_READERS_ENDPOINT>, port: 6379,
  }
], {
  dnsLookup: (address, callback) => callback(null, address),

  scaleReads: 'slave'
})

This code works, but bypasses the cluster for reads, if I understand it correctly:

const Redis = require("ioredis");
var cluster = new Redis({ host: <PRIMARY_RW_ENDPOINT>, port: 6379 })

I can also connect via redis-cli -h <PRIMARY_RW_ENDPOINT>, so I’m sure VPC, Subnet and Security groups are all correct.

I found my mistake, I’m new into ElastiCache and I didn’t realize I need to connect from an EC2 or AWS VPN. I fixed that and it worked.

I guess you’re missing tls.checkServerIdentity and a password, if AUTH is enabled.

I can’t vouch for all of the following, but FYI:

return new IORedis.Cluster(endpoints, {
  // https://github.com/luin/ioredis#special-note-aws-elasticache-clusters-with-tls
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
  // @ts-ignore(TS2554) https://github.com/luin/ioredis/pull/1143
  dnsLookup: (address, callback) => callback(null, address),
  redisOptions: {
    connectionName,
    password,
    // https://github.com/luin/ioredis#reconnect-on-error
    reconnectOnError: function(err) {
      // Only reconnect when the error contains "READONLY"
      // `return 2` to resend failed command after reconnecting
      return err.message.includes('READONLY')
    },
    showFriendlyErrorStack: true,
    tls: {
      checkServerIdentity: (/*host, cert*/) => {
        // skip certificate hostname validation
        return undefined
      }
    }
  },
  slotsRefreshTimeout: 3000
})

FWIW, I know this issue is re: clustered but I was fighting with this as well (in-transit encryption on, passworded redis) and this connection string finally got me going, I expect it’d work with a cluster as well:

const redis = new Redis({
  host: redisHost,
  port: redisPort,
  password: redisPassword,
  tls: {
    checkServerIdentity: (servername, cert) => {
      // skip certificate hostname validation
      return undefined;
    },
  },
});

It’s not working with https://github.com/bitnami/bitnami-docker-redis-cluster

fixes like checkServerIdentity returning undefined, DNS lookup, and other proposed fixes. ioRedis version: 4.28.1

The following works for me.

Redis version: 5.0.4 on AWS ElasticCache Clustered with TLS and AUTH enabled. ioredis version: 4.16.0

Code to connect:

const redis = new Redis.Cluster(
            [{ "host": <ELASTI_CACHE_CONFIGURATION_ENDPOINT> }], {
                dnsLookup: (address, callback) => callback(null, address),
                redisOptions: {
                    tls: true,
                    password: <ELASTI_CACHE_REDIS_AUTH>
                }
            });

Make sure you are in the right VPC, Subnet and Security group to connect to ElastiCache along with the correct IAM role