首页 > 解决方案 > 如何找到 Redis 中可用的最大连接数以及使用的连接数和免费的连接数?

问题描述

我们正在使用 Spring Boot 应用程序中的 Redis,并且我们正像洪水一样低于警报

Exception occurred while querying cache : class org.springframework.data.redis.RedisConnectionFailureException Message: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the poolCause: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the poolMessage:Could not get a resource from the pool",

是因为它们在 Redis 服务器中没有连接吗?或任何其他原因?

如何找到最大可用连接数?如何找到有多少是免费的?

标签: springspring-bootcachingredisjedis

解决方案


无法从池中获取资源

您在客户端的 Jedis 池中的连接已用完。可能的修复:

  1. pool.returnResource()如果您不这样做,请正确返回到池的连接 ( )。不要在不需要它们时握住它们。不要定期断开连接。确保 commons-pool 版本至少为1.6.
  2. 增加池大小。

    JedisPoolConfig poolConfig = new JedisPoolConfig();
    poolConfig.setMaxTotal(...);
    
  3. 增加没有可用连接时的等待时间。

    poolConfig.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    poolConfig.setMaxWait(...);
    

更新

有关服务器端限制,请参见此处:https ://stackoverflow.com/a/51539038/78569


推荐阅读