@@ -27,15 +27,19 @@ private void initializeSlotsCache(Set<HostAndPort> nodes) {
2727 JedisPool jp = new JedisPool (hostAndPort .getHost (),
2828 hostAndPort .getPort ());
2929 this .nodes .put (hostAndPort .getHost () + hostAndPort .getPort (), jp );
30- discoverClusterNodesAndSlots (jp );
30+ Jedis jedis = jp .getResource ();
31+ try {
32+ discoverClusterNodesAndSlots (jedis );
33+ } finally {
34+ jp .returnResource (jedis );
35+ }
3136 }
32-
3337 }
3438
35- private void discoverClusterNodesAndSlots (JedisPool jp ) {
36- String localNodes = jp . getResource () .clusterNodes ();
39+ private void discoverClusterNodesAndSlots (Jedis jedis ) {
40+ String localNodes = jedis .clusterNodes ();
3741 for (String nodeInfo : localNodes .split ("\n " )) {
38- HostAndPort node = getHostAndPortFromNodeLine (nodeInfo );
42+ HostAndPort node = getHostAndPortFromNodeLine (nodeInfo , jedis );
3943 JedisPool nodePool = new JedisPool (node .getHost (), node .getPort ());
4044 this .nodes .put (node .getHost () + node .getPort (), nodePool );
4145 populateNodeSlots (nodeInfo , nodePool );
@@ -63,8 +67,12 @@ private void processSlot(String slot, JedisPool nodePool) {
6367 }
6468 }
6569
66- private HostAndPort getHostAndPortFromNodeLine (String nodeInfo ) {
70+ private HostAndPort getHostAndPortFromNodeLine (String nodeInfo , Jedis currentConnection ) {
6771 String stringHostAndPort = nodeInfo .split (" " , 3 )[1 ];
72+ if (":0" .equals (stringHostAndPort )) {
73+ return new HostAndPort (currentConnection .getClient ().getHost (),
74+ currentConnection .getClient ().getPort ());
75+ }
6876 String [] arrayHostAndPort = stringHostAndPort .split (":" );
6977 return new HostAndPort (arrayHostAndPort [0 ],
7078 Integer .valueOf (arrayHostAndPort [1 ]));
0 commit comments