Properly close jedis connection in case of exceptions

This commit is contained in:
Nelson Rodrigues
2014-07-28 11:45:34 -07:00
parent d52cc06b72
commit c81bdc0849

View File

@@ -126,20 +126,24 @@ public class JedisSentinelPool extends Pool<Jedis> {
log.fine("Connecting to Sentinel " + hap);
Jedis jedis = null;
try {
Jedis jedis = new Jedis(hap.getHost(), hap.getPort());
jedis = new Jedis(hap.getHost(), hap.getPort());
if (master == null) {
master = toHostAndPort(jedis
.sentinelGetMasterAddrByName(masterName));
log.fine("Found Redis master at " + master);
jedis.disconnect();
break outer;
}
} catch (JedisConnectionException e) {
log.warning("Cannot connect to sentinel running @ " + hap
+ ". Trying next one.");
}
} finally {
if (jedis != null) {
jedis.close();
}
}
}
try {