redis长时间未请求,无法自动重连,报异常org.springframework.data.redis.RedisSystemException

org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: io.netty.channel.unix.Errors$NativeIoException: readAddress(..) failed: Connection re

set by peer

at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74)

添加配置

spring:

redis:

lettuce:

pool:

max-active: 8

max-idle: 8

min-idle: 2 # 保持最小空闲连接数

max-wait: 1000ms

time-between-eviction-runs: 30000 # 空闲连接检测周期(毫秒)

redisconfig配置增加

复制代码
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
   RedisStandaloneConfiguration serverConfig = new RedisStandaloneConfiguration(host, port);
   serverConfig.setPassword(password);

   LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
         .commandTimeout(Duration.ofSeconds(5))  // 增加命令超时时间
         .shutdownTimeout(Duration.ofSeconds(2))  // 增加关闭超时时间
         .clientOptions(ClientOptions.builder()
               .autoReconnect(true)
               .disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS)  // 断开连接时拒绝命令
               .pingBeforeActivateConnection(true)  // 连接前PING测试
               .build())
         .build();

   LettuceConnectionFactory factory = new LettuceConnectionFactory(serverConfig, clientConfig);
   factory.setValidateConnection(true);  // 在工厂级别设置连接验证
   return factory;
}
相关推荐
2401_884454151 分钟前
Python测试代码如何实现自解释_使用pytest描述性命名规范
jvm·数据库·python
.柒宇.4 分钟前
Redis哨兵模式搭建
数据库·redis·哨兵
dinglu1030DL10 分钟前
Go语言怎么格式化时间_Go语言time.Format教程【详解】
jvm·数据库·python
环流_13 分钟前
Redis单线程但效率高且快
数据库·redis·缓存
m0_6245785914 分钟前
SQL数据分析如何剔除极端异常值_配合窗口函数检测偏离度
jvm·数据库·python
tkevinjd15 分钟前
MySQL1:分层架构
数据库·mysql·缓存
贫民窟的勇敢爷们20 分钟前
SpringBoot整合MyBatis-Plus极致实战,高效实现数据库CRUD与分页条件查询
数据库·spring boot·mybatis
2401_8800714021 分钟前
Redis怎样查询集群的整体健康状态_使用cluster info指令查看槽位覆盖率与节点状态
jvm·数据库·python
2301_8159019722 分钟前
Go语言如何写负载均衡器_Go语言负载均衡器实战教程【完整】
jvm·数据库·python
Mahir0826 分钟前
Redis 三大缓存问题:穿透、击穿、雪崩的原理与完整解决方案
数据库·redis·缓存·面试·大厂面试题