spring – Jedis,无法获得jedis连接:无法从池中获取资源

前端之家收集整理的这篇文章主要介绍了spring – Jedis,无法获得jedis连接:无法从池中获取资源前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我已经看到几个线程中的答案,但没有为我工作,因为偶尔会出现问题,如果有任何人有任何想法,请问这个问题.

我使用的是jedis版本2.8.0,Spring Data redis版本1.7.5.和我们的缓存应用程序的redis服务器版本2.8.4.

我有多个缓存,用redis保存,get请求是从redis完成的.我使用spring数据redis API来保存和获取数据.

所有保存和获取工作正常,但偶尔低于例外:

Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool | org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the poolorg.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:198)
org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:345)
org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:129)
org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:92)
org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:79)
org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:191)
org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:166)
org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:88)
org.springframework.data.redis.core.DefaultHashOperations.get(DefaultHashOperations.java:49)

我的redis配置类:

@Configuration
public class RedisConfiguration {

@Value("${redisCentralCachingURL}")
private String redisHost;

@Value("${redisCentralCachingPort}")
private int redisPort;

@Bean
public StringRedisSerializer stringRedisSerializer() {
  StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
  return stringRedisSerializer;
}

@Bean
JedisConnectionFactory jedisConnectionFactory() {
  JedisConnectionFactory factory = new JedisConnectionFactory();
  factory.setHostName(redisHost);
  factory.setPort(redisPort);
  factory.setUsePool(true);
  return factory;
}

@Bean
public RedisTemplaterequired all serialization done during impl
  redisTemplate.setKeySerializer(stringRedisSerializer());
  //`redisTemplate.setHashKeySerializer(stringRedisSerializer());
  redisTemplate.setHashValueSerializer(new GenericSnappyRedisSerializer());
  redisTemplate.afterPropertiesSet();
  return redisTemplate;
}

@Bean
public RedisCacheManager cacheManager() {
  RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate());
  redisCacheManager.setTransactionAware(true);
  redisCacheManager.setLoadRemoteCachesOnStartup(true);
  redisCacheManager.setUsePrefix(true);
  return redisCacheManager;
 }

 }

有没有人遇到过这个问题或对此有任何想法,为什么会发生这种情况?

最佳答案
我们遇到了与RxJava相同的问题,应用程序运行良好,但过了一段时间后,再也无法从池中获取任何连接.经过几天的调试,我们终于找出了导致问题的原因:

redisTemplate.setEnableTransactionSupport(true)

不知何故导致spring-data-redis不释放连接.我们需要对MULTI / EXEC的事务支持,但最终改变了实现以摆脱这个问题.

我们仍然不知道这是一个错误错误的使用方式.

原文链接:https://www.f2er.com/spring/432530.html

猜你在找的Spring相关文章