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;
}
相关推荐
HAPPY酷14 分钟前
Kafka 和Redis 在系统架构中的位置
redis·kafka·系统架构
Leo.yuan36 分钟前
数据库同步是什么意思?数据库架构有哪些?
大数据·数据库·oracle·数据分析·数据库架构
Kookoos42 分钟前
ABP VNext 与 Neo4j:构建基于图数据库的高效关系查询
数据库·c#·.net·neo4j·abp vnext
云之兕1 小时前
MyBatis 的动态 SQL
数据库·sql·mybatis
gaoliheng0061 小时前
Redis看门狗机制
java·数据库·redis
?ccc?1 小时前
MySQL主从复制与读写分离
数据库·mysql
会飞的Anthony2 小时前
数据库优化实战分享:高频场景下的性能调优技巧与案例解析
数据库
潘yi.3 小时前
Redis哨兵模式
数据库·redis·缓存
行止63 小时前
MySQL主从复制与读写分离
linux·数据库·mysql