Not able to connect to redis cluster from docker container

Viewed 1493

I am trying to setup Redis cluster. The configuration is the bare minimum setup of the cluster. I am using docker-compose to run my application. But it always throwing the following error. However, when I connect Redis to an external tool it gets connected successfully.

ClusterAllFailedError: Failed to refresh slots cache

const db = new Redis.Cluster([{
    host: "redis",
    port: 6379
}]) 

I can see Redis master and replica instance on docker container

master

container ID - 8a7f4d9fc877        
image - bitnami/redis:latest          
ports - 0.0.0.0:32862->6379/tcp                          
name - mogus_redis_1

slave

container ID - f04433e04de5        
image - bitnami/redis:latest          
ports - 0.0.0.0:32863->6379/tcp                          
name - mogus_redis-replica_1

yml file

redis:
    image: "bitnami/redis:latest"
    ports:
    - 6379
    environment:
      REDIS_REPLICATION_MODE: master
      ALLOW_EMPTY_PASSWORD: "yes"
    volumes:
    - redis-data:/bitnami

  redis-replica:
    image: "bitnami/redis:latest"
    ports:
    - 6379
    depends_on:
    - redis
    environment:
      REDIS_REPLICATION_MODE: slave
      REDIS_MASTER_HOST: redis
      REDIS_MASTER_PORT_NUMBER: 6379
      ALLOW_EMPTY_PASSWORD: "yes"
1 Answers

You are not using a Redis Cluster, just a single master and a replica. That being the case, your app should just use the singleinstance class, which I assume is something like this:

const db = new Redis([{
    host: "redis",
    port: 6379
}])
Related