gpt4 book ai didi

java - JedisConnectionFactory 超时

转载 作者:可可西里 更新时间:2023-11-01 11:14:13 30 4
gpt4 key购买 nike

有没有办法像我们为 HttpRequestFactory 那样在 JedisConnFactory 中配置读取超时?我已经为 JedisConnFactory 配置了超时属性,如下所示。它是否包括连接超时读取超时

final JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisHost);
redisConnectionFactory.setTimeout(10000);
redisConnectionFactory.setPort(port);
redisConnectionFactory.setUsePool(true);
redisConnectionFactory.afterPropertiesSet();

@Bean(name = "redisCacheManager")
public CacheManager cacheManager(final RedisTemplate<String,Object> redisTemplate) {
final RedisCacheManager manager = new RedisCacheManager(redisTemplate());
manager.setDefaultExpiration(Long.parseLong(expiryInSecs));
return manager;
}

@Bean(name="redisTemplate")
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(stringRedisSerializer());
redisTemplate.setHashKeySerializer(stringRedisSerializer());
redisTemplate.setValueSerializer(stringRedisSerializer());
redisTemplate.setHashValueSerializer(stringRedisSerializer());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}

最佳答案

您可以使用 JedisClientConfiguration .它有一个生成器 JedisClientConfigurationBuilder其中包含分别具有连接超时和读取超时属性。

JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder().readTimeout(readTimeout).
connectTimeout(connectTimeout).build();

然后您可以使用 JedisConnectionFactory 之一接受 JedisClientConfiguration 的构造函数。

关于java - JedisConnectionFactory 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57424436/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com