【问题标题】:how to configure timeout of JedisConnectionFactory base on spring boot framework如何基于 Spring Boot 框架配置 JedisConnectionFactory 的超时时间
【发布时间】:2015-08-06 23:53:56
【问题描述】:

我用的是springboot,搞不清配置超时连接redis。

目前,我的配置是:

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:

@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抓包,发现2秒后redis断开了,不是我上面代码设置的5秒。

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

请问,我该怎么做?

【问题讨论】:

    标签: redis timeout spring-boot


    【解决方案1】:

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

    spring.redis.timeout=5000
    

    【讨论】:

    猜你喜欢
    • 2011-05-08
    • 2020-03-28
    • 2014-06-21
    • 2021-02-19
    • 2021-02-15
    • 1970-01-01
    • 2019-02-17
    • 2019-03-01
    • 2023-03-10
    相关资源
    最近更新 更多