4

I am getting error while trying to returnResources from the jedis pool.The code are as follow.

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);
}
Kundan Ray
  • 370
  • 1
  • 4
  • 15

1 Answers1

5

I was closing the redis client elsewhere in my application that's why when I was going to close redis client then it was throwing exception.Also I have noted that we should be more careful while using redis client. If we get the resource from redis pool then we will also must have to disconnect them after using it.If we are not doing this then client will be inreasing and after meeting maxSizeClient limit it will also throw exception.I made changes in the start method of 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);
    }
}
Kundan Ray
  • 370
  • 1
  • 4
  • 15