How to config redis-cluster when use spring-data-redis 1.7.0.M1

前端 未结 1 1199
慢半拍i
慢半拍i 2021-01-19 23:41

I use spring-data-redis version 1.7.0.M1,and jedis version 2.8.0 Here is my configuration

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 00:04

    Basically all that is needed is setting the inital collection of cluster nodes in RedisClusterConfiguration and provide that one to JedisConnectionFactory or LettuceConnectionFactory.

    @Configuration
    class Config {
    
        List clusterNodes = Arrays.asList("127.0.0.1:30001", "127.0.0.1:30002", "127.0.0.1:30003");
    
        @Bean
        RedisConnectionFactory connectionFactory() {
          return new JedisConnectionFactory(new RedisClusterConfiguration(clusterNodes));
        }
    
        @Bean
        RedisTemplate redisTemplate(RedisConnectionFactory factory) {
    
          // just used StringRedisTemplate for simplicity here.
          return new StringRedisTemplate(factory);
        }
    }
    

    Spring Boot will provide configuration properties (spring.redis.cluster.nodes, spring.redis.cluster.max-redirects) for working with Redis cluster in the next release. See commit/166a27 for details.

    The spring-data-examples repository already contains an example of Spring Data Redis cluster support.

    0 讨论(0)
提交回复
热议问题