SpringBoot集成Redis Sentinel模式,报错:RedisCommandExecutionException: ERR unknown command `SENTINEL`
一、前提
SpringBoot项目集成Redis Sentinel模式,报错:
- application.yml配置
# 哨兵模式
spring:
redis:
password: 12**56
sentinel:
master: mymaster
nodes: *.*.*.196:6379,*.*.*.197:6380,*.*.*.198:6381
二、错误信息
2022-07-20 17:45:40.861 ERROR 33392 --- [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisException: java.util.concurrent.ExecutionException: io.lettuce.core.RedisCommandExecutionException: ERR unknown command `SENTINEL`, with args beginning with: `get-master-addr-by-name`, `mymaster`, ] with root cause
io.lettuce.core.RedisCommandExecutionException: ERR unknown command `SENTINEL`, with args beginning with: `get-master-addr-by-name`, `mymaster`,
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:118) ~[lettuce-core-5.0.5.RELEASE.jar:na]
关键报错信息:
RedisCommandExecutionException
ERR unknown command 'SENTINEL'
with args beginning with: 'get-master-addr-by-name', 'mymaster', ]
三、原因
yml配置文件中,sentinel模式下,nodes的配置是哨兵的配置,不是redis的配置。所有,应该更正为哨兵IP:哨兵port
正确配置:
# 哨兵模式
spring:
redis:
password: 12**56
sentinel:
master: mymaster
nodes: *.*.*.196:26379,*.*.*.197:26380,*.*.*.198:26381
# 26379,26380,26381:为哨兵对应的端口

浙公网安备 33010602011771号