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.
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.)Security Group
, NACL
allows the connection to ElastiCache
port (6379
is the default) from your Compute Subnet
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.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With