Skip to content

Commit

Permalink
[fix #31] ec2 서버 redis 인증 문제 (#32)
Browse files Browse the repository at this point in the history
* [chore] : redis 설정 파일 내 인증 로직 추가

* [chore] : Q엔티티 파일 gitignore에 추가
  • Loading branch information
hyun2371 authored Aug 12, 2024
1 parent 22a3146 commit d35edde
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ out/
/src/main/resources/application.yml
.DS_Store
/src/test/resources/application.yml
/src/main/generated/
14 changes: 12 additions & 2 deletions src/main/java/com/dnd/gongmuin/common/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
Expand All @@ -17,9 +18,18 @@ public class RedisConfig {
@Value("${spring.data.redis.port}")
private int port;

@Value("${spring.data.redis.password:}")
private String password;

@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(host, port);
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(host);
config.setPort(port);
if (!password.isEmpty()) {
config.setPassword(password);
}
return new LettuceConnectionFactory(config);
}

@Bean
Expand All @@ -31,4 +41,4 @@ public RedisTemplate<String, Object> redisTemplate() {

return redisTemplate;
}
}
}

0 comments on commit d35edde

Please sign in to comment.