生菜RedisCommandTimeoutException问题

时间:2018-12-24 06:26:22

标签: spring-boot redis lettuce

我使用以下生菜池配置连接到Redis:

   #  other properties
   spring.redis.timeout=10000
   spring.redis.test-on-borrow=true
   spring.redis.test-while-idle=true
   spring.redis.lettuce.pool.max-active=100
   spring.redis.lettuce.pool.max-idle=100
   spring.redis.lettuce.pool.min-idle=5
   spring.redis.lettuce.pool.max-wait=5000

我的配置类:

@Bean
LettuceConnectionFactory lettuceConnectionFactory(RedisProperties
redisProperties) {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setTestOnReturn(true);
    poolConfig.setMaxIdle(redisProperties.getMaxIdle());
    poolConfig.setMinIdle(redisProperties.getMinIdle());
    poolConfig.setMaxWaitMillis(redisProperties.getMaxWait());
    poolConfig.setMaxTotal(redisProperties.getMaxActive());
    poolConfig.setTestOnBorrow(redisProperties.isTestOnBorrow());
    poolConfig.setTestWhileIdle(redisProperties.isTestWhileIdle());

    LettuceClientConfiguration lettuceClientConfiguration =
    LettucePoolingClientConfiguration.builder()
        .commandTimeout(Duration.ofMillis(redisProperties.getTimeout()))
        .poolConfig(poolConfig)
        .build();
    //  other config
    LettuceConnectionFactory lettuceConnectionFactory = new
    LettuceConnectionFactory(redisSentinelConfiguration,
    lettuceClientConfiguration);
    lettuceConnectionFactory.afterPropertiesSet();
    return lettuceConnectionFactory;
}

它在启动时可以工作,但是在一段时间(此时间段内没有任何操作)后发出RedisCommandTimeoutException。由于testOnborrow和testOnIdle不起作用。有人知道吗?

0 个答案:

没有答案