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;
}
相关推荐
天宇_任19 分钟前
Mysql数据库迁移到GaussDB注意事项
数据库·mysql·gaussdb
鼠鼠我捏,要死了捏1 小时前
生产环境Redis缓存穿透与雪崩防护性能优化实战指南
redis·cache
xiep14383335103 小时前
Ubuntu 安装带证书的 etcd 集群
数据库·etcd
Java小白程序员4 小时前
Spring Framework:Java 开发的基石与 Spring 生态的起点
java·数据库·spring
老虎06274 小时前
数据库基础—SQL语句总结及在开发时
数据库·sql·oracle
曾经的三心草5 小时前
微服务的编程测评系统11-jmeter-redis-竞赛列表
redis·jmeter·微服务
爱掘金的土拨鼠6 小时前
国产化dm数据库锁表解锁
数据库
庖丁解java6 小时前
N个Utils
数据库
努力努力再努力wz7 小时前
【c++深入系列】:万字详解模版(下)
java·c++·redis
Mr. zhihao7 小时前
SQL LEFT JOIN 与 WHERE 条件的隐藏坑
数据库·sql