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;
}
相关推荐
weixin_580614007 分钟前
模型持久化不会提升准确率:揭秘训练集误用导致的“虚假精度”陷阱
jvm·数据库·python
2401_887724508 分钟前
Layui弹出层layer.tab如何监听标签页切换的具体序号
jvm·数据库·python
2501_9142459324 分钟前
构建 Go CLI 应用的最佳实践:纯 Go 交互式命令行库选型与使用指南
jvm·数据库·python
m0_5145205725 分钟前
Go语言变量如何声明和使用_Go语言变量定义完整教程【通俗】
jvm·数据库·python
weixin_5860614637 分钟前
CSS Grid布局如何解决图片溢出网格单元_设置object-fit与网格尺寸.txt
jvm·数据库·python
秋940 分钟前
数据库对比同步工具,快速比较开发库与生产库直接的差别,并自动生成存在差异的sql语句
数据库·oracle
Greyson11 小时前
CSS Grid布局如何解决图片溢出网格单元_设置object-fit与网格尺寸.txt
jvm·数据库·python
Whitemeen太白1 小时前
查询子级分类、父级分类、叶子节点分类(MySQL / Oracle )
数据库·mysql·oracle
C#程序员一枚1 小时前
高可用(High Availability, HA)
数据库·c#
2401_883600251 小时前
Redis如何查询特定用户的排名_利用ZREVRANK指令获取ZSet降序名次
jvm·数据库·python