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;
}
相关推荐
DaveVV19 分钟前
苍穹外卖-阿里云OSS使用
数据库·阿里云·云计算
盖世英雄酱5813634 分钟前
InnoDB中的一致性读取,锁读的应用场景
java·数据库·后端
科技圈快讯1 小时前
共筑智慧城市新生态!YashanDB与荣科科技完成兼容互认证
数据库·oracle
沉默的煎蛋1 小时前
深入理解 Redis SDS:高效字符串存储的秘密
开发语言·前端·数据库·架构·bootstrap·html·maven
LF3_1 小时前
redis,tar.gz安装后,接入systemctl报错解决
java·数据库·redis
数据知道1 小时前
数据库:一文掌握 Oracle 的各种指令(Oracle指令备忘)
数据库·oracle
会喷火才能叫火山1 小时前
集群环境下Redis 商品库存系统设计
java·数据库·redis·缓存
weixin_307779132 小时前
Linux下用Bash Shell脚本和mysql命令行程序实现带多组参数和标签的MySQL数据库批量数据导出程序
linux·开发语言·数据库·mysql·bash
是阿建吖!2 小时前
【MySQL】复合查询
android·数据库·mysql
老马啸西风2 小时前
Neo4j GDS-02-graph-data-science 插件库安装实战笔记
数据结构·数据库·笔记·算法·neo4j·