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;
}
相关推荐
·云扬·30 分钟前
【PmHub后端篇】PmHub整合TransmittableThreadLocal (TTL)缓存用户数据
java·开发语言·缓存
♡喜欢做梦1 小时前
【MySQL】联合查询
数据库·mysql
撸码到无法自拔2 小时前
加速LLM大模型推理,KV缓存技术详解与PyTorch实现
人工智能·pytorch·python·深度学习·缓存
老华带你飞2 小时前
音乐网站|基于SprinBoot+vue的音乐网站(源码+数据库+文档)
java·前端·数据库·vue.js·论文·毕设·音乐网站
gadiaola7 小时前
MySQL从入门到精通(三):MySQL数据类型、SQL语言—DDL
数据库·sql·mysql·database
muxue1788 小时前
关于almalinux分区配置:
linux·运维·数据库
海天胜景9 小时前
Asp.Net Core IIS发布后PUT、DELETE请求错误405
数据库·后端·asp.net
凯子坚持 c9 小时前
【金仓数据库征文】金仓数据库 KES:MySQL 迁移实用指南
数据库·金仓数据库 2025 征文·数据库平替用金仓
小刘|10 小时前
Redis 中简单动态字符串(SDS)的深入解析
数据库·redis·bootstrap
怀君11 小时前
Flutter——数据库Drift开发详细教程(四)
数据库·flutter