redis.clients.jedis.exceptions.JedisException: 无法 return 资源到池中

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

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

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 客户端然后它抛出 exception.Also 我注意到我们在使用 redis 客户端时应该更加小心。如果我们从 Redis 池中获取资源,那么我们还必须在使用 it.If 后断开它们的连接,我们没有这样做,那么客户端将会增加,并且在达到 maxSizeClient 限制后,它也会抛出 exception.I 所做的更改在 Publisher 的启动方法中。

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);
    }
}