snaag / TIL

https://github.com/snaag/todo3/issues
3 stars 0 forks source link

22-12-12-MON #24

Open snaag opened 1 year ago

snaag commented 1 year ago
snaag commented 1 year ago

Spring boot, Redis (Jedis)

Cluster 안썼던 Redis 를 Cluster 를 사용하도록 바꾸기

https://stackoverflow.com/questions/41918560/redis-cluster-integration-with-spring-boot

AS-IS

@Bean
public RedisConnectionFactory redisConnectionFactory() {
  return new JedisConnectionFactory(new RedisStandaloneConfiguration(host, port));
}

TO-BE

스크린샷 2022-12-13 오전 1 21 27
@Bean
public RedisConnectionFactory redisConnectionFactory() {
  return new JedisConnectionFactory(redisConfiguration());
}
스크린샷 2022-12-13 오전 1 22 41
@Bean
RedisClusterConfiguration redisConfiguration() {
  RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(nodes);
  redisClusterConfiguration.setMaxRedirects(maxRedirect);

  return redisClusterConfiguration;
}