Search code examples
spring-bootspring-data-redismissing-features

Alternative way to define cluster nodes property in spring-data-redis


I was trying to use spring-data-redis in my project. When I configure redis nodes in yaml file like:

spring:
  redis:
    cluster:
      max-redirects: 2
      nodes: host1:6379,host1:6380,host1:6381

Then, spring-data-redis creates the JedisConnectionFactory for cluster internally. But If I try to configure by following ways:

spring:
  redis:
    cluster:
      max-redirects: 2
      nodes: 
        - host1:6379
        - host1:6380
        - host1:6381

Then, I must have to create the bean of JedisConnectionFactory for cluster in my application.

I guess current version of spring-data-redis not supporting representation of number of nodes in array way in yaml to create cluster.

My suggestion is can spring-boot/spring-data-redis developer supports above format of yaml to create redis cluster internally?


Solution

  • If you check here, it is possible to supply the hostAndPort as an ugly looking array like this, separate from spring.redis properties group;

    clusterHostAndPorts:
      - host1:6379
      - host1:6380
      - host1:6381
    

    Tested on my local, and it does work, the way you are asking is not supported, can see it here, then here, and then finally here.

    HostAndPort need to be seperated by ':'.

    Host and Port String needs to specified as host:port