gpt4 book ai didi

java - redis.clients.jedis.exceptions.JedisException : Could not return the resource to the pool

转载 作者:行者123 更新时间:2023-11-30 08:16:28 25 4
gpt4 key购买 nike

我在尝试从 jedis 池中返回资源时遇到错误。代码如下。

Jedis publisherJedis = jedispool.getResource();
if(!redisPassword.equals(""))
publisherJedis.auth(redisPassword);
publisherJedis.publish(channel,data);
log.debug("Publisher jedis is connected: " + publisherJedis.isConnected());
log.debug("Jsondata is added into the queue " + data);
try {
jedispool.returnResource(publisherJedis);
jedispool.destroy();
publisherJedis.close();
} catch (Exception e) {
e.printStackTrace();
log.error("Exception occured in returing resource " + e);
}

最佳答案

我在我的应用程序的其他地方关闭了 redis 客户端,这就是为什么当我要关闭 redis 客户端然后它抛出异常时。我还注意到我们在使用 redis 客户端时应该更加小心。如果我们从 redis 池中获取资源,那么我们也必须在使用后断开它们。如果我们不这样做,那么客户端将会增加,并且在达到 maxSizeClient 限制后它也会抛出异常。我在启动方法中进行了更改出版商。

public void start(JedisPool jedispool, Jedis publisherJedis, String channel,String data, String redisPassword)
{
if(!redisPassword.equals(""))
publisherJedis.auth(redisPassword);
publisherJedis.publish(channel,data);
log.debug("Jsondata is added into the queue " +data);
try{
publisherJedis.close();
log.debug(" Is Jedis connected " +publisherJedis.isConnected());
if(publisherJedis.isConnected())
publisherJedis.disconnect();
log.debug(" After disconnecting: is redis connected " +publisherJedis.isConnected());
}catch(Exception e){
log.debug("Error occured " +e);
}
}

关于java - redis.clients.jedis.exceptions.JedisException : Could not return the resource to the pool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28300702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com