From efe572a429ea402e923ce2a73908bd425aa879c8 Mon Sep 17 00:00:00 2001 From: Victor Zeng Date: Mon, 30 Nov 2015 10:58:51 +0800 Subject: [PATCH] Update --- pom.xml | 4 +-- .../pool/redis/RedisConnectionFactory.java | 25 +++++++++++-------- .../pool/redis/RedisSentinelConnPool.java | 6 ++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 1b4c7dc..0a6c1e7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.darkphoenixs connectionpool-client - 1.1 + 1.2 jar ConnectionPoolClient @@ -20,7 +20,7 @@ 0.8.2.1 1.1.1 - 2.7.3 + 2.8.0 11.2.0.1.0 UTF-8 diff --git a/src/main/java/org/darkphoenixs/pool/redis/RedisConnectionFactory.java b/src/main/java/org/darkphoenixs/pool/redis/RedisConnectionFactory.java index 6377541..4606620 100644 --- a/src/main/java/org/darkphoenixs/pool/redis/RedisConnectionFactory.java +++ b/src/main/java/org/darkphoenixs/pool/redis/RedisConnectionFactory.java @@ -139,17 +139,22 @@ public Jedis createConnection() throws Exception { Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), this.connectionTimeout, this.soTimeout); - jedis.connect(); - if (null != this.password) { - jedis.auth(this.password); - } - if (this.database != 0) { - jedis.select(this.database); - } - if (this.clientName != null) { - jedis.clientSetname(this.clientName); + try { + jedis.connect(); + if (null != this.password) { + jedis.auth(this.password); + } + if (this.database != 0) { + jedis.select(this.database); + } + if (this.clientName != null) { + jedis.clientSetname(this.clientName); + } + } catch (Exception je) { + jedis.close(); + throw je; } - + return jedis; } diff --git a/src/main/java/org/darkphoenixs/pool/redis/RedisSentinelConnPool.java b/src/main/java/org/darkphoenixs/pool/redis/RedisSentinelConnPool.java index 8ec56fc..6276e42 100644 --- a/src/main/java/org/darkphoenixs/pool/redis/RedisSentinelConnPool.java +++ b/src/main/java/org/darkphoenixs/pool/redis/RedisSentinelConnPool.java @@ -314,8 +314,8 @@ private HostAndPort initSentinels(Set sentinels, log.fine("Found Redis master at " + master); break; } catch (Exception e) { - log.warning("Cannot connect to sentinel running @ " + hap - + ". Trying next one."); + log.warning("Cannot get master address from sentinel running @ " + hap + + ". Reason: " + e + ". Trying next one."); } finally { if (jedis != null) { jedis.close(); @@ -382,7 +382,7 @@ public Jedis getResource() { // connected to the correct master return jedis; } else { - returnConnection(jedis); + invalidateResource(jedis); } } }