Skip to content

Commit

Permalink
fix: redis config 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdtkdgns committed Aug 6, 2023
1 parent 0be9882 commit 917849b
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions src/main/java/Backend/teampple/infra/redis/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.time.Duration;

@Configuration
@EnableRedisRepositories(enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP)
@EnableRedisRepositories(
enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP,
keyspaceNotificationsConfigParameter = "")
public class RedisConfig {

@Value("${spring.redis.host}")
Expand All @@ -28,15 +30,12 @@ public class RedisConfig {
@Value("${spring.redis.password}")
private String password;

// redis와 connection을 생성
@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisConfig =
new RedisStandaloneConfiguration(host, 6379);
RedisStandaloneConfiguration redisConfig = new RedisStandaloneConfiguration(host, port);

// if (password != null && !password.isBlank()) {
// redisConfig.setPassword(password);
// }
// if (redisPassword != null && !redisPassword.isBlank())
// redisConfig.setPassword(redisPassword);

LettuceClientConfiguration clientConfig =
LettuceClientConfiguration.builder()
Expand All @@ -46,32 +45,10 @@ public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisConfig, clientConfig);
}

// @Bean
// public RedisConnectionFactory redisConnectionFactory(){
// RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration()
// .master("mymaster")
// .sentinel(host,26379)
// .sentinel(host,26380)
// .sentinel(host,26381);
//
// if (password != null && !password.isBlank()) {
// redisSentinelConfiguration.setPassword(password);
// }
//
// LettuceClientConfiguration clientConfig =
// LettuceClientConfiguration.builder()
// .commandTimeout(Duration.ofSeconds(1))
// .shutdownTimeout(Duration.ZERO)
// .build();
// return new LettuceConnectionFactory(redisSentinelConfiguration, clientConfig);
// }

// RedisConnection에서 넘겨준 byte 값을 객체 직렬화
@Bean
public RedisTemplate<?,?> redisTemplate(){
RedisTemplate<byte[], byte[]> redisTemplate = new RedisTemplate<>();
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
// redis-cli을 통해 직접 데이터를 보려고 할 때 알아볼 수 없는 형태로 출력 방지
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
return redisTemplate;
Expand Down

0 comments on commit 917849b

Please sign in to comment.