spring - 如何检查一个 REDIS 服务器可以给客户端的总 redis 连接数?

标签 spring caching redis spring-data-redis

我们正在使用 REDIS 缓存,并使用 Spring-Redis 模块,我们在应用程序配置中设置了 maxActiveConnections 10,但有时在我的应用程序中会看到以下错误

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

是因为在 Redis 服务器中没有更多连接给我的应用程序还是任何其他原因,任何人都可以对此提出建议吗?

注意:它们是 15 个应用程序,它们使用同一个 Redis 服务器来存储数据,我的意思是 15 个应用程序只需要来自这个单个 redis 服务器的连接,现在我们将每个应用程序的 maxActiveConnections 设置为 10 15 个应用程序

最佳答案

要检查有多少客户端连接到 Redis,您可以使用 redis-cli 并键入此命令:redis> INFO 更具体地说是 info Clients命令。

192.168.8.176:8023> info Clients
# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

从Jedis源码来看,好像是因为以下原因导致异常:

  1. Exhausted cache://异常是由一个耗尽的池引起的
  2. or//否则,异常是由实现的 activateObject()ValidateObject()
  3. 引起的

这是 Jedis getResource 方法的代码片段:

  public T getResource() {
    try {
      return internalPool.borrowObject();
    } catch (NoSuchElementException nse) {
      if (null == nse.getCause()) { // The exception was caused by an exhausted pool
        throw new JedisExhaustedPoolException(
            "Could not get a resource since the pool is exhausted", nse);
      }
      // Otherwise, the exception was caused by the implemented activateObject() or ValidateObject()
      throw new JedisException("Could not get a resource from the pool", nse);
    } catch (Exception e) {
      throw new JedisConnectionException("Could not get a resource from the pool", e);
    }
  }

关于spring - 如何检查一个 REDIS 服务器可以给客户端的总 redis 连接数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49526991/

相关文章:

redis - 无法使用 redis-cli 从 Redis 获取匹配的 key

java - 如何在Java中使用Redis命令 “bitcount”

node.js - 缓存数据库中的项目是否存在

java - Hibernate的ManyToMany简单使用

java - Spring 服务的可选嵌套注入(inject)

java - Spring 休息-发布文件

asp.net - ASP.net 应用程序的内存与缓存

Spring OAuth2 问题

ruby-on-rails - rails 3.2 : Pre-render (bake) a new page cache immediately after expiry?

caching - 将 Redis 与 Guzzle 的缓存插件结合使用