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

南楼画角 提交于 2019-12-01 18:28:21

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<String> 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<String, String> 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!