300x250
반응형
안녕하세요. J4J입니다.
이번 포스팅은 redis에서 발생했던 이슈에 대해 적어보는 시간을 가져보려고 합니다.
이슈 원인
redis를 사용하기 위해 서버 구축부터 시작하여 spring 프로젝트에 다양한 설정들을 추가해볼 수 있습니다.
제목과 관련된 이슈는 여러 가지 설정들을 해보면서 제가 마주했던 것 중 하나입니다.
먼저 저는 spring 프로젝트 내부에 redis 사용 환경 설정을 해보면서 다음과 같은 에러 메세지를 확인할 수 있었습니다.
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1805)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1736)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1538)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.lambda$getConnection$0(LettuceConnectionFactory.java:1518)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.doInLock(LettuceConnectionFactory.java:1478)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1515)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:1199)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:1006)
...
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to <ip>/<unresolved>:6379
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350)
at io.lettuce.core.RedisClient.connect(RedisClient.java:215)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:112)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:112)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1734)
...
Caused by: io.lettuce.core.RedisCommandExecutionException: NOAUTH HELLO must be called with the client already authenticated, otherwise the HELLO <proto> AUTH <user> <pass> option can be used to authenticate the client and select the RESP protocol version at the same time
at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:147)
at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:116)
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120)
at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111)
at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:745)
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:680)
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:597)
중간에 있는 에러를 확인해보면 getConnection과 관련된 이슈인 것을 어느정도 짐작해 볼 수 있었고 결국 redis와 통신할 수 없는 상태라는 것을 알 수 있었습니다.
서버 내부에 접근하여 cli를 통해 명령어를 입력할 경우 문제가 전혀 없었기에 spring 프로젝트와 redis 서버 간의 설정 중 잘못된 것이 무엇인지 위주로 확인했습니다.
반응형
이슈 해결 방법
이슈를 해결하기 위해서는 원인을 파악하면서 짐작했던 것과 같이 잘못된 설정을 고쳐야 했습니다.
저는 spring에서 redis를 사용하기 위해 다음과 같이 설정을 했었습니다.
// application.yml
spring:
data:
redis:
host: xxx.xxx.xxx.xxx
port: 6379
하지만 이 부분에서 놓쳤던 것은 redis에 password 설정이 되어 있는 것입니다.
그래서 다음과 같이 redis 설정에 password를 추가하였더니 올바르게 동작하는 것을 확인했습니다.
// application.yml
spring:
data:
redis:
host: xxx.xxx.xxx.xxx
port: 6379
password: xxxxxx
이상으로 redis에서 발생했던 이슈에 대해 간단하게 알아보는 시간이었습니다.
읽어주셔서 감사합니다.
728x90
반응형
'Spring > SpringBoot' 카테고리의 다른 글
[SpringBoot] Redis 테스트 환경 구축하기 (2) - Test Container (0) | 2024.07.27 |
---|---|
[SpringBoot] Redis 테스트 환경 구축하기 (1) - Embedded (0) | 2024.07.07 |
[SpringBoot] Querydsl에서 페이징 처리하기 (0) | 2024.06.05 |
[SpringBoot] Shedlock을 이용하여 분산 환경 배치 처리하기 (0) | 2024.05.19 |
[SpringBoot] Redis 사용하기 (4) - Redis Cache Manager 사용하기 (0) | 2024.05.15 |
댓글