当前位置: 首页 > 知识库问答 >
问题:

绝地,无法获取绝地连接:无法从池中获取资源

欧阳乐生
2023-03-14

我使用的是jedis版本2.8.0和Spring Data redis版本1.7.5。和redis服务器版本2.8.4。

我有多个缓存得到保存在redis和获取请求是从redis完成的。我正在使用spring data redis API来保存和获取数据。

所有的save和get都可以正常工作,但偶尔geting会低于exception:

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 RedisTemplate<String, Object> redisTemplate() {
  RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
  redisTemplate.setConnectionFactory(jedisConnectionFactory());
  redisTemplate.setExposeConnection(true);
  // No serializer required 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;
 }

 }

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

共有1个答案

柳宪
2023-03-14

我们在RxJava中遇到了同样的问题,应用程序运行良好,但过了一段时间后,再也无法从池中查询到任何连接。经过几天的调试,我们终于弄清楚了是什么导致了这个问题:

redisTemplate.setEnableTransactionSupport(true)

导致spring-data-redis无法释放连接。我们需要对MULTI/EXEC的事务支持,但最终更改了实现以解决这个问题。

我们仍然不知道这是不是一个错误或错误的用法在我们这边。

 类似资料:
  • 我们的应用程序使用并连接到,以下是我如何获得jedis资源: 这是我的绝地说唱者(统一资源管理): 是Jedis实例的容器,下面是我如何使用它: 请注意,可能非常大(例如可以达到最大8KB)。 每次我重启我们的应用程序,所有的redis连接都是正常的,但是几个小时后,异常出来了。频率变得越来越高,然后所有到Redis的连接都断开了,可以创建新的连接。 以下是我的配置: 异常堆栈跟踪:

  • 我每5分钟运行一次批处理作业,我不希望其他节点运行同一个作业,因此我使用绝地锁将一个对象锁定5分钟。这样,如果另一个节点试图运行同一个作业,它们就不会得到锁。工作是在获得锁后开始的,当我试图从Redis读取它时,我得到以下异常情况: 这是我的密码 spring启动应用程序。属性文件 作业在开始时执行以下代码以获得锁 之后,redis仓库类试图读取特定模式的值... 这就是我在日志中看到的完全例外。

  • 我成功地获得了20个请求的响应,但无法获得其余10个请求的响应。我面临的问题是,在前20个请求使用了20个连接之后,其余的10个请求无法从池中获得jedis连接,因此我得到以下例外情况: 我已经在网上搜索,但没有找到解决办法。有人能帮我吗?

  • 问题内容: 我已经在几个线程中看到了答案,但对我却没有解决,而且由于我的问题偶尔发生,因此问这个问题是否有人有任何想法。 我正在使用jedis版本2.8.0,Spring Data Redis版本1.7.5。和redis服务器版本2.8.4用于我们的缓存应用程序。 我有多个缓存保存在redis中,并且从redis获得请求。我正在使用spring数据redis API保存和获取数据。 所有保存和获取

  • 我需要一些关于我遇到的一些问题的帮助,当尝试连接到redis使用spring Boot。 我正在使用以下重新配置: 和下面的类,我正在尝试创建一个单元测试来测试我的连接: 我知道这里有一个类似的问题,但我还没有要求的分数来评论,我尝试了他们的建议,我仍然得到同样的结果。下面是我的pom.xml: 下面是我的属性文件: redis.clients.jedis.exceptions.jedisconn

  • Redis.Properties spring-redis.xml 代码 控制器