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 小时前
及时做APP开发实战(十二)-LazyForEach懒加载优化实践
数据库·鸿蒙
龙仔7255 小时前
人大金仓KingbaseES V8 手动单库备份&恢复操作笔记
数据库·笔记·oracle·人大金仓
宠友信息7 小时前
消息序号如何保证即时通讯源码聊天记录稳定加载
java·spring boot·redis·python·mysql·uni-app
夏贰四8 小时前
数据库迁移怎样降低人力投入?数据库迁移怎么实现全量增量同步?
数据库·数据库迁移
汇智信科8 小时前
图谱、向量、关键词、SQL多路一体,FastKG垂域召回率100%拉满
网络·数据库·ai编程·汇智信科·hsim·fastclaw·汇智龙虾
hold?fish:palm9 小时前
RDB全量快照备份
c++·redis·后端
笨蛋不要掉眼泪10 小时前
MySQL架构揭秘:慢查询日志详解
数据库·mysql·架构
pulinzt10 小时前
Tableau的基础使用
数据库·numpy
糖果店的幽灵10 小时前
【langgraph 从入门到精通graphApi 篇】LangGraphAPI 方式调用 - 初识与核心概念
数据库·人工智能·langgraph
TlSfoward11 小时前
TLSFOWARD TLS指纹
开发语言·数据库·爬虫·搜索引擎·https·php