场景
当redis集群master节点宕机后,对应的slaver节点变为master提供服务,但是Lettuce客户端还是会出现无法连接异常。
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: /172.0.0.1:7001
Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
at io.netty.channel.unix.Errors.throwConnectException(Errors.java:124) ~[netty-transport-native-unix-common-4.1.51.Final.jar!/:4.1.51.Final]
原因分析
spring-data-redis包中实现的Lettuce客户端时,默认没有开启客户端刷新功能。Jedis客户端默认实现了集群刷新功能。
处理办法
spring配置中开启自动刷新功能,spring boot2.3.0以上版本。
spring:
application:
name: lizz-gateway
#***********************redis***********************
redis: #redis配置
lettuce:
cluster:
refresh:
adaptive: true #自动刷新集群 默认false关闭
# period: 10M #定时刷新