Skip to content

Commit 179498d

Browse files
committed
Merge pull request #527 from xetorthio/node_parsing
Fix #526. Node parsing error uppon :0
2 parents b35e1f9 + a69dd4e commit 179498d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/main/java/redis/clients/jedis/JedisClusterConnectionHandler.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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]));

src/test/java/redis/clients/jedis/tests/JedisClusterTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public void setUp() throws InterruptedException {
4444
// ---- configure cluster
4545

4646
// add nodes to cluster
47-
node1.clusterMeet("127.0.0.1", nodeInfo1.getPort());
4847
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
4948
node1.clusterMeet("127.0.0.1", nodeInfo3.getPort());
5049

0 commit comments

Comments
 (0)