Zasadniczo wszystko, co jest potrzebne, to ustawienie początkowej kolekcji węzłów klastra w RedisClusterConfiguration i przekaż go firmie JedisConnectionFactory lub 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 zapewni właściwości konfiguracyjne (spring.redis.cluster.nodes , spring.redis.cluster.max-redirects ) do pracy z klastrem Redis w następnej wersji. Zobacz commit/166a27, aby uzyskać szczegółowe informacje.
Repozytorium spring-data-examples zawiera już przykład obsługi klastra Spring Data Redis.