티스토리 뷰

Skill/spring

RedisConfig.java

진열사랑 2025. 1. 13. 10:07

@Configuration
public class RedisConfig {
@Value("${redis.cluster.nodes}")
List<String> redisNodeList;

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();

redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
redisTemplate.setConnectionFactory(connectionFactory);

return redisTemplate;
}

@Bean
public RedisConnectionFactory prdRedisConnectionFactory() {
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(redisNodeList);

// topology 자동 업데이트 옵션 추가
// enablePeriodicRefresh(topology 정보 감시 주기) default value : 60s
ClusterTopologyRefreshOptions clusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
.enableAllAdaptiveRefreshTriggers() // MOVED, ASK, PERSISTENT_RECONNECTS, UNCOVERED_SLOT, UNKOWN_NODE trigger시 refresh 수행
.enablePeriodicRefresh(Duration.ofMinutes(30L)) // topology 정보 감시 주기 설정 -> 30분
.build();
ClientOptions clientOptions = ClusterClientOptions.builder()
.topologyRefreshOptions(clusterTopologyRefreshOptions)
.build();

// topology 옵션 및 timeout 세팅
LettuceClientConfiguration clientConfigurations = LettuceClientConfiguration.builder()
.commandTimeout(Duration.ofSeconds(30L)) // command Timeout설정 -> 30초
.clientOptions(clientOptions)
.build();

return new LettuceConnectionFactory(redisClusterConfiguration, clientConfigurations);
}

@Bean
public ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}

'Skill > spring' 카테고리의 다른 글

ServiceConfig.java  (0) 2025.01.13
ServiceAOP.java  (0) 2025.01.13
PropertiesCheck.java  (0) 2025.01.13
JasyptConfig.java  (0) 2025.01.13
AsyncConfig.java  (0) 2025.01.13
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함