Skip to content

ClusterAllFailedError: Failed to refresh slots cache. #1984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Kirti2198 opened this issue May 29, 2025 · 0 comments
Open

ClusterAllFailedError: Failed to refresh slots cache. #1984

Kirti2198 opened this issue May 29, 2025 · 0 comments

Comments

@Kirti2198
Copy link

ioredis: ^5.5.0

Trying to connect to redis enterprise cluster instance but getting this error again and again
I tried to connect using redis-cli its working fine but when i am trying to use ioredis and below code its giving error
These are the timeouts I am using

Application runtime settings

REDIS_CLUSTER=true
REDIS_SSL=true
CACHE_TTL=7200
SHORT_TTL=7200
MEDIUM_TTL=14400
LONG_TTL=28800

REDIS_KEY_SCAN_LIMIT=50000
REDIS_CONNECT_TIMEOUT=10000
REDIS_CLUSTER_CONNECT_TIMEOUT=20000
REDIS_CLUSTER_SLOT_REFRESH_INTERVAL=5000
REDIS_CLUSTER_SLOT_REFRESH_TIMEOUT=60000
REDIS_CLUSTER_RETRY_BASE_DELAY=100
REDIS_CLUSTER_RETRY_MAX_DELAY=5000
REDIS_CLUSTER_KEY_SCAN_LIMIT=50000

export function getRedisInstance(connectionName: string) {
let redisInstance;
const startTime = process.hrtime();
console.log(redis connection:${connectionName});
try {
if (cache.cluster && cache.tls) {
redisInstance = new Redis.Cluster(
[
{
host: cache.hostname,
port: cache.port,
},
],
{
dnsLookup: (address, callback) => callback(null, address, 4),
redisOptions: {
...(cache.tls && {
tls: {
host: cache.hostname,
servername: cache.hostname,
rejectUnauthorized: false,
checkServerIdentity: (servername, cert) => {
// skip certificate hostname validation
return undefined;
},
},
}),
password: cache.password,
connectionName: connectionName,
showFriendlyErrorStack: true,
connectTimeout: redisClusterConfig.connectTimeout,
keepAlive: 1,
},
slotsRefreshInterval: redisClusterConfig.slotsRefreshInterval, // Increase interval to 5 seconds
slotsRefreshTimeout: redisClusterConfig.slotsRefreshTimeout, // Increase timeout to 60 seconds
enableReadyCheck: true,
clusterRetryStrategy: (times) => {
const delay = Math.min(times * redisClusterConfig.retryBaseDelay, redisClusterConfig.retryMaxDelay);
console.log(Retrying after ${delay}ms);
return delay;
},
}
);
// Log errors for debugging
redisInstance.on('ready', () => {
// Log request time taken
console.log(
Total time taken to connnect to redis server: ${DateTimeUtility.prototype.parseHrtimeToSeconds(process.hrtime(startTime))} seconds
);
console.log('Cluster is ready!');
});
redisInstance.on('error', (err) => {
console.log(Redis error: ${err});
});
} else if (!cache.cluster && cache.tls) {
const url = rediss://:${cache.password}@${cache.hostname}:${cache.port};
redisInstance = new Redis(url, {
connectionName: connectionName,
});
} else {
redisInstance = new Redis({
port: cache.port,
host: cache.hostname,
family: 4,
password: cache.password,
connectTimeout: redisConfig.connectTimeout,
connectionName: connectionName,
});
}
} catch (error) {
console.log(Redis connection creation error, connection name: ${connectionName}, ${error} );
console.log(connection details, host:${cache.hostname},port:${cache.port});
throw error;
}
return redisInstance;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant