如何基于spring boot框架配置JedisConnectionFactory的超时时间 [英] how to configure timeout of JedisConnectionFactory base on spring boot framework
本文介绍了如何基于spring boot框架配置JedisConnectionFactory的超时时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是springboot,我很困惑配置连接redis的超时时间.
I'm using springboot, I'm confused to configure the timeout to connect redis.
目前,我的配置是:
application.yml:
application.yml:
spring.redis.host: myhost
spring.redis.port: 6379
spring.redis.pool.max-idle: 8
spring.redis.pool.min-idle: 0
spring.redis.pool.max-active: 8
spring.redis.pool.max-wait: -1
StringRedisDao.java:
StringRedisDao.java:
@Autowired
public StringRedisDao(final StringRedisTemplate template, final ObjectMapper mapper) {
if (template.getConnectionFactory() instanceof JedisConnectionFactory) {
((JedisConnectionFactory) template.getConnectionFactory()).getShardInfo().setTimeout(5000);
((JedisConnectionFactory) template.getConnectionFactory()).setTimeout(5000);
}
this.template = template;
this.mapper = mapper;
}
我使用wireshark抓包,发现redis在2秒后就断开了,而不是我上面代码中设置的5秒.
I use wireshark to capture the packets, and I found that the redis was disconnected after 2 seconds, not 5 seconds as I set in the code above.
因此,我无法执行redis查询时间超过2秒的请求.
Because of this, I cannot perform a requests that the query time of redis is more than 2 seconds.
请问,我该怎么做?
推荐答案
还有一个配置设置可以放在 application.properties 中:
There is also a configuration setting you can put in application.properties:
spring.redis.timeout=5000
这篇关于如何基于spring boot框架配置JedisConnectionFactory的超时时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文