redis - Jedis 连接未被释放

标签 redis jedis

我在使用带有 Jedis 连接池的 Redis 时遇到问题。

我看到的行为是,在建立连接后,它们不会被释放回连接池。

我知道这一点是因为使用 redis-cli client list 命令我可以看到连接仍然存在。

有人可以检查我的 jedis 连接池,让我知道这是否会导致问题。

     <spring:bean id="ElasticachePoolConfig" name="ElasticachePoolConfig" class="redis.clients.jedis.JedisPoolConfig" >

        <!-- Minimum number of idle connections to Redis - these can be seen as always open and ready to serve -->
        <spring:property name="minIdle" value="${redis.minIdle}" />

        <!-- Number of connections to Redis that just sit there and do nothing -->
        <spring:property name="maxIdle" value="${redis.maxIdle}" />

        <!-- Maximum number of active connections that can be allocated from this pool at the same time -->
        <spring:property name="maxTotal" value="${redis.maxTotal}" />

        <!-- The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor.--> 
        <spring:property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" />

        <!-- The minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle connection evictor -->
        <spring:property name="softMinEvictableIdleTimeMillis" value="${redis.softMinEvictableIdleTimeMillis}" />

        <!-- The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception -->
        <spring:property name="maxWaitMillis" value="${redis.maxWaitMillis}" />

        <!-- Maximum number of connections to test in each idle check -->
        <spring:property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" />

        <!-- Tests whether connection is dead when connection retrieval method is called -->
        <spring:property name="testOnBorrow" value="${redis.testOnBorrow}" />

        <!-- Tests whether connection is dead when returning a connection to the pool -->
        <spring:property name="testOnReturn" value="${redis.testOnReturn}" />

        <!-- Tests whether connections are dead during idle periods -->
        <spring:property name="testWhileIdle" value="${redis.testWhileIdle}" />

        <!-- Idle connection checking period -->
        <spring:property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" />

        <spring:property name="blockWhenExhausted" value="${redis.blockWhenExhausted}" />

     </spring:bean>

其中属性设置如下...

redis.port=6379
redis.timeout=2000
redis.ttl=600
redis.host=localhost
redis.repeater.maxRetries=3
redis.repeater.millisBetweenRetries=2000
redis.minIdle=5
redis.maxIdle=10
redis.maxTotal=8
redis.minEvictableIdleTimeMillis=30000
redis.softMinEvictableIdleTimeMillis=-1
redis.maxWaitMillis=5000
redis.numTestsPerEvictionRun=10
redis.testOnBorrow=true
redis.testOnReturn=true
redis.testWhileIdle=false
redis.timeBetweenEvictionRunsMillis=50000
redis.blockWhenExhausted=true

最佳答案

您的 maxIdle 设置大于您的 maxTotal 设置,因此实际上不会在空闲时释放任何连接。该池将维护 maxIdle 连接。

JedisPool 在内部使用 Apache Commons Pooling。参见 this answer关于 maxIdlemaxTotal 之间的区别。

关于redis - Jedis 连接未被释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46032586/

相关文章:

node.js - Redis Cloud 和 connect-redis : the client is closed

java - 如何在 Windows 上测试运行 Memurai

java - redis 好像服务器关闭了连接

spring - 在Kubernetes中部署Redis的Spring boot应用--Jedis Connection Refused错误

redis - 使用 jedis 客户端从 spring 中获取 aws Redis 集群

ruby-on-rails - Rails 5.2 中的 Action Cable 抛出 NoMethodError

c# - Redis 与应用内缓存

redis - 无法更改端口号

redis - 我需要关闭我的 Redis 连接吗?

redis - 无法使用jedis连接到redis