0

In most examples including this Jedis example the Jedis pool is created in the try..catch parenthesis which I think disposes it:

try(Jedis jedis = jedisPool.getResource())
{
    some code
}

For me this is not possible because I need to throw errors while still using the Jedis pool, depending on result from Redis. So for my this is just

Jedis jedis = jedisPool.getResource()

Question is how best to dispose the object? Is it jedis.disconnect? jedis.quit? jedis = null?

There are some similar questions but not exactly same. One about error it gives, another about increasing pool, another about threading.

sazzad
  • 5,740
  • 6
  • 25
  • 42
developerX
  • 33
  • 4
  • The link you gave is not *official* example. Please be careful and respectful about stating so. – sazzad Jan 14 '20 at 02:09

1 Answers1

1

Simply jedis.close(). See Jedis - When to use returnBrokenResource()

You used to be expected to use jedisPool.returnBrokenResource(jedis) or jedisPool.returnResource(jedis), but jedis.close() takes care of it.

See Jedis.java.

Jedis jedis = null;
try {
    jedis = jedisPool.getResource();

...
}catch (JedisConnectionException e) {
...
}catch (Exception e){
...
} finally {
    if (jedis != null)
        jedis.close();
}
LeoMurillo
  • 6,048
  • 1
  • 19
  • 34