Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ioredis - ClusterAllFailedError: Failed to refresh slots cache

I'm dealing with a ClusterAllFailedError: Failed to refresh slots cache. issue from ioredis and Elasticache. This is my clustering config

const clusterOptions = {
    enableReadyCheck: true,
    retryDelayOnClusterDown: 300,
    retryDelayOnFailover: 1000,
    retryDelayOnTryAgain: 3000,
    slotsRefreshTimeout: 200000000000000,
    clusterRetryStrategy: (times) => Math.min(times * 1000, 10000),
    dnsLookup: (address, callback) => callback(null, address),
    scaleReads: 'slave',
    showFriendlyErrorStack: true,
    redisOptions: {
        keyPrefix: config.queue.prefix,
        autoResubscribe: true,
        autoResendUnfulfilledCommands: true
    }
}

const redisClientInstance = new Redis.Cluster([{ host: '', port: ''}], clusterOptions);

But trying to access the Redis always results in a Failed refresh slots cache. Anyone else dealt with this issue?

Thank you.

like image 391
Cyberomin Avatar asked Aug 04 '19 23:08

Cyberomin


1 Answers

The following works for me.

Redis version: 5.0.4 on AWS ElastiCache 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>
                }
            });

When you launch ElastiCache, you will need to specify one or more Subnet Group (generally private Subnets) and the Security Group. When you run the above code from any compute (Lambda, EC2 etc.), you need to ensure the following

  • ElastiCache is reachable from your Compute (Put the compute in a Subnet which can communicate with the Subnet of the ElastiCache in the same VPC. If the compute and Elasticache are on different VPCs, ensure VPC peering enabled between them.)
  • Ensure the Security Group, NACL allows the connection to ElastiCache port (6379 is the default) from your Compute Subnet
  • Finally ensure the Compute can assume an IAM Role(EC2 instance profile, Lambda Role etc) which has appropriate access to ElastiCache. In case you are running on an EC2 instance, make sure your code uses the temporary credentials of the Role assigned in the EC2 instance profile.
like image 70
GSSwain Avatar answered Sep 18 '22 20:09

GSSwain