Skip to content

Commit

Permalink
Merge pull request redis#527 from xetorthio/node_parsing
Browse files Browse the repository at this point in the history
Fix redis#526. Node parsing error uppon :0
  • Loading branch information
xetorthio committed Feb 5, 2014
2 parents b35e1f9 + a69dd4e commit 179498d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ private void initializeSlotsCache(Set<HostAndPort> nodes) {
JedisPool jp = new JedisPool(hostAndPort.getHost(),
hostAndPort.getPort());
this.nodes.put(hostAndPort.getHost() + hostAndPort.getPort(), jp);
discoverClusterNodesAndSlots(jp);
Jedis jedis = jp.getResource();
try {
discoverClusterNodesAndSlots(jedis);
} finally {
jp.returnResource(jedis);
}
}

}

private void discoverClusterNodesAndSlots(JedisPool jp) {
String localNodes = jp.getResource().clusterNodes();
private void discoverClusterNodesAndSlots(Jedis jedis) {
String localNodes = jedis.clusterNodes();
for (String nodeInfo : localNodes.split("\n")) {
HostAndPort node = getHostAndPortFromNodeLine(nodeInfo);
HostAndPort node = getHostAndPortFromNodeLine(nodeInfo, jedis);
JedisPool nodePool = new JedisPool(node.getHost(), node.getPort());
this.nodes.put(node.getHost() + node.getPort(), nodePool);
populateNodeSlots(nodeInfo, nodePool);
Expand Down Expand Up @@ -63,8 +67,12 @@ private void processSlot(String slot, JedisPool nodePool) {
}
}

private HostAndPort getHostAndPortFromNodeLine(String nodeInfo) {
private HostAndPort getHostAndPortFromNodeLine(String nodeInfo, Jedis currentConnection) {
String stringHostAndPort = nodeInfo.split(" ", 3)[1];
if (":0".equals(stringHostAndPort)) {
return new HostAndPort(currentConnection.getClient().getHost(),
currentConnection.getClient().getPort());
}
String[] arrayHostAndPort = stringHostAndPort.split(":");
return new HostAndPort(arrayHostAndPort[0],
Integer.valueOf(arrayHostAndPort[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public void setUp() throws InterruptedException {
// ---- configure cluster

// add nodes to cluster
node1.clusterMeet("127.0.0.1", nodeInfo1.getPort());
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
node1.clusterMeet("127.0.0.1", nodeInfo3.getPort());

Expand Down

0 comments on commit 179498d

Please sign in to comment.