首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何基于spring boot框架配置JedisConnectionFactory超时

如何基于spring boot框架配置JedisConnectionFactory超时
EN

Stack Overflow用户
提问于 2015-05-25 21:18:56
回答 1查看 14.4K关注 0票数 6

我使用的是springboot,我不知道如何配置超时来连接redis。

目前,我的配置是:

application.yml:

代码语言:javascript
复制
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:

代码语言:javascript
复制
@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秒。

因此,我无法执行redis查询时间超过2秒的请求。

我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2015-09-23 00:14:06

还有一个配置设置可以放在application.properties中:

代码语言:javascript
复制
spring.redis.timeout=5000
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30439378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档