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;
}
相关推荐
IT规划师2 分钟前
Redis 核心机制 | 过期删除策略:惰性+定期+主动(二)
redis·.net10·过期删除策略
城北徐宫17 小时前
MySQL数据类型整理
数据库·mysql
数据库小学妹17 小时前
数据库容量规划:四个数与扩容触发线
运维·数据库·后端
时间的拾荒人17 小时前
Redis Cluster 集群详解:分片算法、搭建、故障处理与扩容实战
数据库·redis·算法·集群
纆兰20 小时前
MySQL的多表查询
数据库·mysql
七夜zippoe20 小时前
Nexent 模型配置:4 字段与 9 个槽位
数据库·人工智能·模型·nexent
进击的荆棘21 小时前
MySQL——表的操作
数据库·mysql
nice_lcj5201 天前
MySQL 慢查询与 EXPLAIN:怎么定位、怎么优化
java·数据库·后端·mysql
IT规划师1 天前
Redis 核心机制 | 键生命周期与 TTL 管理
redis·.net