SpringBoot整合redis客户端超时怎么解决
作者:RiverSoul
时间:2023-05-01
浏览:1
Redis Assistant
Redis Assistant 是一款为Redis设计的高效可视化管理与监控工具,提供多种操作模式,高效处理服务器数据。日常使用里的持续防护和信息管理会更突出,适合把安全控制放进长期使用流程中的场景。
¥19
Windows/macOS/Linux
2026-08-22
问题在开发的时候,使用到Lettuce连接redis,一段时间后不操作,再去操作redis,会报连接超时错误,在其重连后又可使用。原因是:Lettuce自适应拓扑刷新(Adaptiveupdates)与定时拓扑刷新(Periodicupdates)是默认关闭的导致问题的出现解决的方案方法一:1、重写连接工厂实例,更改其LettuceClientConfiguration为开启拓扑更新@ConfigurationpublicclassRedisConfig{@AutowiredprivateRedisPro
本文目录
问题
在开发的时候,使用到Lettuce连接redis,一段时间后不操作,再去操作redis,会报连接超时错误,在其重连后又可使用。
原因是:Lettuce 自适应拓扑刷新(Adaptive updates)与定时拓扑刷新(Periodic updates) 是默认关闭的导致问题的出现
解决的方案
方法一:
1、重写连接工厂实例,更改其LettuceClientConfiguration 为开启拓扑更新
@Configuration
public class RedisConfig {
@Autowired
private RedisProperties redisProperties;
//这是固定的模板
//自己定义了一个RedisTemplate
@Bean
@SuppressWarnings("all")
public RedisTemplate redisTemplate(@Qualifier("lettuceConnectionFactoryUvPv") RedisConnectionFactory factory) {
RedisTemplate template = new RedisTemplate<>();
template.setConnectionFactory(factory);
//Json序列化配置
Jackson2JsonRedisSerializer 2、SpringBoot2.3.x后,可使用配置文件中开启lettuce的拓扑刷新
lettuce: pool: max-active: 20 max-wait: -1ms max-idle: 10 min-idle: 2 cluster: refresh: adaptive: true #20秒自动刷新一次 period: 20
方法二:
更改连接redis的连接方式,使用jedis连接
org.springframework.boot spring-boot-starter-data-redis io.lettuce lettuce-core redis.clients jedis
配置文件
spring:
redis:
password: xxx
host: 172.16.0.x
port: 6579
timeout: 5000
jedis:
pool:
#最大连接数据库连接数,设 0 为没有限制
max-active: 8
#最大等待连接中的数量,设 0 为没有限制
max-idle: 8
#最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
max-wait: -1ms
#最小等待连接中的数量,设 0 为没有限制
min-idle: 0
#lettuce:
#pool:
#max-active: ${redis.config.maxTotal:1024}
#max-idle: ${redis.config.maxIdle:50}
#min-idle: ${redis.config.minIdle:1}
#max-wait: ${redis.config.maxWaitMillis:5000}
作者最新文章
漫蛙漫画app下载安装最新版本
2026-10-13 13:19
漫蛙漫画官网入口链接
2026-10-13 13:19
漫蛙2漫画APP最新版本下载免费安装
2026-10-13 13:17
漫蛙漫画官网正版登录入口
2026-10-13 13:15
Windows安装Docker教程:启用WSL2并运行第一个容器验证
2026-10-08 17:47
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多










































