Fix Jedis connection failure detection.

This commit is contained in:
Tux 2013-12-06 21:27:28 -05:00
parent facd8de553
commit 7c35aad456
1 changed files with 4 additions and 2 deletions

View File

@ -253,12 +253,14 @@ public class RedisBungee extends Plugin implements Listener {
if (!redisServer.equals("")) { if (!redisServer.equals("")) {
pool = new JedisPool(new JedisPoolConfig(), redisServer, redisPort, Protocol.DEFAULT_TIMEOUT, redisPassword); pool = new JedisPool(new JedisPoolConfig(), redisServer, redisPort, Protocol.DEFAULT_TIMEOUT, redisPassword);
// Test the connection // Test the connection
Jedis rsc = pool.getResource(); Jedis rsc = null;
try { try {
rsc = pool.getResource();
rsc.exists(String.valueOf(System.currentTimeMillis())); rsc.exists(String.valueOf(System.currentTimeMillis()));
getLogger().log(Level.INFO, "Successfully connected to Redis."); getLogger().log(Level.INFO, "Successfully connected to Redis.");
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
pool.returnBrokenResource(rsc); if (rsc != null)
pool.returnBrokenResource(rsc);
getLogger().log(Level.WARNING, "Failed to connect to your Redis server! RedisBungee will still work, albeit with reduced functionality.", e); getLogger().log(Level.WARNING, "Failed to connect to your Redis server! RedisBungee will still work, albeit with reduced functionality.", e);
pool.destroy(); pool.destroy();
pool = null; pool = null;