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;
}
相关推荐
正在走向自律5 分钟前
金仓数据库KingbaseES基础语法详解与实践指南
数据库·国产数据库·ddl·dml·kingbasees·sql语法·电科金仓
alonewolf_995 分钟前
MySQL全局优化详解与8.0新特性全面解读
数据库·mysql
雪域迷影6 分钟前
Windows11上安装Redis服务和Redis可视化客户端
windows·redis
ASS-ASH8 分钟前
快速处理虚拟机磁盘扩容问题
linux·数据库·vmware·虚拟机·磁盘扩容
爱写bug的野原新之助13 分钟前
数据库及navicat工具
数据库·网络爬虫·工具
青云交13 分钟前
Java 大视界 -- 基于 Java+Redis Cluster 构建分布式缓存系统:实战与一致性保障(444)
java·redis·缓存·缓存穿透·分布式缓存·一致性保障·java+redis clus
数据知道16 分钟前
一文掌握 MongoDB 存储引擎 WiredTiger 的原理
数据库·mongodb·数据库架构
Full Stack Developme21 分钟前
Mycat 2 实现 MySQL 读写分离,并且实现 主从同步
android·数据库·mysql
我是人✓25 分钟前
Spring IOC入门
java·数据库·spring
Hello.Reader26 分钟前
PyFlink DataStream 程序骨架、常用 Source/Sink、状态(State)、与 Table/SQL 互转一篇搞定
数据库·sql·linq