spring-projects/spring-data-redis

getClusterConnection.clusterGetNodes always return 1 node

senolatac opened this issue · 1 comments

My configuration looks like:

spring.data.redis.password=...
spring.data.redis.username=default
spring.data.redis.ssl.enabled=false
spring.data.redis.cluster.nodes=127.0.0.1:16379,127.0.0.1:17379,127.0.0.1:18379,127.0.0.1:19379,127.0.0.1:20379,127.0.0.1:21379

Bean looks like:

    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new JdkSerializationRedisSerializer());
        redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
        redisTemplate.setEnableTransactionSupport(true);
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }

And docker-compose looks like:

version: '3.8'

services:
  redis-node-0:
    image: docker.io/bitnami/redis-cluster:7.2
    volumes:
      - ./redis-data/redis-cluster_data-0:/bitnami/redis/data
    ports:
      - "${REDIS_CLUSTER_PORT_0}:${REDIS_CLUSTER_PORT_0}"
    environment: &redis-environment
      REDIS_CLUSTER_DYNAMIC_IPS: no
      REDIS_PORT_NUMBER: ${REDIS_CLUSTER_PORT_0}
      REDIS_CLUSTER_ANNOUNCE_PORT: ${REDIS_CLUSTER_PORT_0}
      REDIS_PASSWORD: ${REDIS_MASTER_PASSWORD}
      REDIS_USERNAME: ${REDIS_CLI_USER}
      #REDIS_DISABLE_DEFAULT_USER: true
      REDIS_CLUSTER_ANNOUNCE_IP: ${REDIS_MASTER_HOST}
      REDIS_NODES: redis-node-0:${REDIS_CLUSTER_PORT_0} redis-node-1:${REDIS_CLUSTER_PORT_1} redis-node-2:${REDIS_CLUSTER_PORT_2} redis-node-3:${REDIS_CLUSTER_PORT_3} redis-node-4:${REDIS_CLUSTER_PORT_4} redis-node-5:${REDIS_CLUSTER_PORT_5}

  redis-node-1:
    image: docker.io/bitnami/redis-cluster:7.2
    volumes:
      - ./redis-data/redis-cluster_data-1:/bitnami/redis/data
    ports:
      - "${REDIS_CLUSTER_PORT_1}:${REDIS_CLUSTER_PORT_1}"
    environment:
      <<: *redis-environment
      REDIS_PORT_NUMBER: ${REDIS_CLUSTER_PORT_1}
      REDIS_CLUSTER_ANNOUNCE_PORT: ${REDIS_CLUSTER_PORT_1}

  redis-node-2:
    image: docker.io/bitnami/redis-cluster:7.2
    volumes:
      - ./redis-data/redis-cluster_data-2:/bitnami/redis/data
    ports:
      - "${REDIS_CLUSTER_PORT_2}:${REDIS_CLUSTER_PORT_2}"
    environment:
      <<: *redis-environment
      REDIS_PORT_NUMBER: ${REDIS_CLUSTER_PORT_2}
      REDIS_CLUSTER_ANNOUNCE_PORT: ${REDIS_CLUSTER_PORT_2}

  redis-node-3:
    image: docker.io/bitnami/redis-cluster:7.2
    volumes:
      - ./redis-data/redis-cluster_data-3:/bitnami/redis/data
    ports:
      - "${REDIS_CLUSTER_PORT_3}:${REDIS_CLUSTER_PORT_3}"
    environment:
      <<: *redis-environment
      REDIS_PORT_NUMBER: ${REDIS_CLUSTER_PORT_3}
      REDIS_CLUSTER_ANNOUNCE_PORT: ${REDIS_CLUSTER_PORT_3}

  redis-node-4:
    image: docker.io/bitnami/redis-cluster:7.2
    volumes:
      - ./redis-data/redis-cluster_data-4:/bitnami/redis/data
    ports:
      - "${REDIS_CLUSTER_PORT_4}:${REDIS_CLUSTER_PORT_4}"
    environment:
      <<: *redis-environment
      REDIS_PORT_NUMBER: ${REDIS_CLUSTER_PORT_4}
      REDIS_CLUSTER_ANNOUNCE_PORT: ${REDIS_CLUSTER_PORT_4}

  redis-node-5:
    image: docker.io/bitnami/redis-cluster:7.2
    volumes:
      - ./redis-data/redis-cluster_data-5:/bitnami/redis/data
    ports:
      - "${REDIS_CLUSTER_PORT_5}:${REDIS_CLUSTER_PORT_5}"
    depends_on:
      - redis-node-0
      - redis-node-1
      - redis-node-2
      - redis-node-3
      - redis-node-4
    environment:
      <<: *redis-environment
      REDIS_PORT_NUMBER: ${REDIS_CLUSTER_PORT_5}
      REDIS_CLUSTER_ANNOUNCE_PORT: ${REDIS_CLUSTER_PORT_5}
      REDISCLI_AUTH: ${REDIS_CLI_USER}
      REDIS_CLUSTER_REPLICAS: 1
      REDIS_CLUSTER_CREATOR: yes



volumes:
  redis-cluster_data-0:
    driver: local
  redis-cluster_data-1:
    driver: local
  redis-cluster_data-2:
    driver: local
  redis-cluster_data-3:
    driver: local
  redis-cluster_data-4:
    driver: local
  redis-cluster_data-5:
    driver: local

Finally when I try to get all nodes via:


        redisTemplate.getConnectionFactory().getClusterConnection()
                .clusterGetNodes()
                .forEach(x -> System.out.println(x.getHost() + ":" + x.getPort()));

it always return 1 node like 127.0.0.1:19379. Ok node is changing on each run but my expectation is 6 nodes. Is there any suggestion?

solved problem with adding bus-port and important note: bus-port = redis-port + 10000 otherwise it doesn't work.

check here: https://stackoverflow.com/questions/78188348/getclusterconnection-clustergetnodes-always-return-1-node/78192159#78192159