From 003624a9b9c18f7518ec31ba17b20a75f41fa0e1 Mon Sep 17 00:00:00 2001 From: tmixell Date: Wed, 4 Mar 2020 22:04:52 -0500 Subject: [PATCH 1/3] issue #2153 - honor sentinel configuration params within `MasterListener` --- src/main/java/redis/clients/jedis/JedisSentinelPool.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/JedisSentinelPool.java b/src/main/java/redis/clients/jedis/JedisSentinelPool.java index f10f0e6154..0c60ee8aee 100644 --- a/src/main/java/redis/clients/jedis/JedisSentinelPool.java +++ b/src/main/java/redis/clients/jedis/JedisSentinelPool.java @@ -301,7 +301,13 @@ public void run() { while (running.get()) { - j = new Jedis(host, port); + j = new Jedis(host, port, sentinelConnectionTimeout, sentinelSoTimeout); + if (sentinelPassword != null) { + j.auth(sentinelPassword); + } + if (sentinelClientName != null) { + j.clientSetname(sentinelClientName); + } try { // double check that it is not being shutdown From f1f0b374cdc4cab525b956c1b41b95508aa6222b Mon Sep 17 00:00:00 2001 From: tmixell Date: Wed, 4 Mar 2020 22:51:42 -0500 Subject: [PATCH 2/3] 2153 fix formatting --- src/main/java/redis/clients/jedis/JedisSentinelPool.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/JedisSentinelPool.java b/src/main/java/redis/clients/jedis/JedisSentinelPool.java index 0c60ee8aee..bc9d765fe2 100644 --- a/src/main/java/redis/clients/jedis/JedisSentinelPool.java +++ b/src/main/java/redis/clients/jedis/JedisSentinelPool.java @@ -303,8 +303,8 @@ public void run() { j = new Jedis(host, port, sentinelConnectionTimeout, sentinelSoTimeout); if (sentinelPassword != null) { - j.auth(sentinelPassword); - } + j.auth(sentinelPassword); + } if (sentinelClientName != null) { j.clientSetname(sentinelClientName); } From 25c88f5a8edfcd6db46eed5b6ad0fd719f26f704 Mon Sep 17 00:00:00 2001 From: tmixell Date: Sun, 8 Mar 2020 10:07:24 -0400 Subject: [PATCH 3/3] 2153 moving instatiation into try/catch + conditionally close if not null --- .../clients/jedis/JedisSentinelPool.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/redis/clients/jedis/JedisSentinelPool.java b/src/main/java/redis/clients/jedis/JedisSentinelPool.java index bc9d765fe2..9577d47efd 100644 --- a/src/main/java/redis/clients/jedis/JedisSentinelPool.java +++ b/src/main/java/redis/clients/jedis/JedisSentinelPool.java @@ -300,20 +300,19 @@ public void run() { running.set(true); while (running.get()) { - - j = new Jedis(host, port, sentinelConnectionTimeout, sentinelSoTimeout); - if (sentinelPassword != null) { - j.auth(sentinelPassword); - } - if (sentinelClientName != null) { - j.clientSetname(sentinelClientName); - } - try { // double check that it is not being shutdown if (!running.get()) { break; } + + j = new Jedis(host, port, sentinelConnectionTimeout, sentinelSoTimeout); + if (sentinelPassword != null) { + j.auth(sentinelPassword); + } + if (sentinelClientName != null) { + j.clientSetname(sentinelClientName); + } // code for active refresh List masterAddr = j.sentinelGetMasterAddrByName(masterName); @@ -362,7 +361,9 @@ public void onMessage(String channel, String message) { log.debug("Unsubscribing from Sentinel at {}:{}", host, port); } } finally { - j.close(); + if (j != null) { + j.close(); + } } } }