FG
๐Ÿ—„๏ธ Databases

ClusterAllFailedError: Failed to refresh slots cache.

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score63%
63%

Problem

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); })();`

Error Output

error can You help me ?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Fix ClusterAllFailedError in ioredis Configuration

Medium Risk

The error 'ClusterAllFailedError: Failed to refresh slots cache' typically occurs when the Redis cluster nodes are unreachable or misconfigured. This can happen due to incorrect hostnames, ports, or network issues preventing the application from connecting to the cluster nodes.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Verify Redis Cluster Node Configuration

    Ensure that the environment variables REDIS_HOST_1 and REDIS_HOST_2 are correctly set to the valid IP addresses or hostnames of your Redis cluster nodes. Also, confirm that the REDIS_PORT is correct and accessible.

    typescript
    console.log(`Host 1: ${process.env.REDIS_HOST_1}, Port: ${process.env.REDIS_PORT}`);
    console.log(`Host 2: ${process.env.REDIS_HOST_2}, Port: ${process.env.REDIS_PORT}`);
  2. 2

    Check Network Connectivity

    Test the network connectivity to the Redis cluster nodes from the application server. Use tools like `ping` or `telnet` to check if the nodes are reachable on the specified ports.

    bash
    telnet <REDIS_HOST_1> <REDIS_PORT>
    telnet <REDIS_HOST_2> <REDIS_PORT>
  3. 3

    Increase slotsRefreshTimeout

    If the cluster nodes are reachable but the error persists, try increasing the `slotsRefreshTimeout` in the options to allow more time for the slots cache to refresh.

    typescript
    const options = {
        slotsRefreshTimeout: 5000, // Increased timeout
        dnsLookup: (address, callback) => callback(null, address),
        redisOptions: {
            tls: {},
            password: process.env.REDIS_PASS,
        },
    };
  4. 4

    Check Redis Cluster Health

    Use the Redis CLI to check the health of the cluster. Run the command `redis-cli -c -h <REDIS_HOST_1> -p <REDIS_PORT> cluster info` and ensure that all nodes are in a healthy state.

    bash
    redis-cli -c -h <REDIS_HOST_1> -p <REDIS_PORT> cluster info
  5. 5

    Review Redis Logs

    Check the logs of the Redis cluster nodes for any errors or warnings that might indicate issues with node connectivity or configuration. This can provide insights into why the slots cache cannot be refreshed.

    bash
    cat /var/log/redis/redis-server.log

Validation

After applying the fixes, restart your application and monitor the logs for any occurrences of the ClusterAllFailedError. Additionally, ensure that the application can successfully connect to the Redis cluster and perform operations without errors.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

redisiorediscache