Skip to content

Commit 76df52e

Browse files
committed
Merge pull request #668 from HeartSaVioR/fix-build-related-to-change-of-cluster-nodes-output
fix build after CLUSTER NODES output has been changed
2 parents e05eaa2 + 0f472c9 commit 76df52e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/main/java/redis/clients/util/ClusterNodeInformationParser.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import redis.clients.jedis.HostAndPort;
44

55
public class ClusterNodeInformationParser {
6-
private static final String HOST_MYSELF_IDENTIFIER = ":0";
76
private static final String SLOT_IMPORT_IDENTIFIER = "-<-";
87
private static final String SLOT_IN_TRANSITION_IDENTIFIER = "[";
98
public static final int SLOT_INFORMATIONS_START_INDEX = 8;
@@ -36,13 +35,13 @@ private String[] extractSlotParts(String[] nodeInfoPartArray) {
3635
public HostAndPort getHostAndPortFromNodeLine(String[] nodeInfoPartArray,
3736
HostAndPort current) {
3837
String stringHostAndPort = nodeInfoPartArray[HOST_AND_PORT_INDEX];
39-
if (HOST_MYSELF_IDENTIFIER.equals(stringHostAndPort)) {
40-
return current;
41-
}
4238

4339
String[] arrayHostAndPort = stringHostAndPort.split(":");
44-
return new HostAndPort(arrayHostAndPort[0],
45-
Integer.valueOf(arrayHostAndPort[1]));
40+
return new HostAndPort(
41+
arrayHostAndPort[0].isEmpty() ? current.getHost()
42+
: arrayHostAndPort[0],
43+
arrayHostAndPort[1].isEmpty() ? current.getPort() : Integer
44+
.valueOf(arrayHostAndPort[1]));
4645
}
4746

4847
private void fillSlotInformation(String[] slotInfoPartArray,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void setUp() {
1717

1818
@Test
1919
public void testParseNodeMyself() {
20-
String nodeInfo = "9b0d2ab38ee31482c95fdb2c7847a0d40e88d518 :0 myself,master - 0 0 1 connected 0-5460";
20+
String nodeInfo = "9b0d2ab38ee31482c95fdb2c7847a0d40e88d518 :7379 myself,master - 0 0 1 connected 0-5460";
2121
HostAndPort current = new HostAndPort("localhost", 7379);
2222
ClusterNodeInformation clusterNodeInfo = parser
2323
.parse(nodeInfo, current);
@@ -44,7 +44,7 @@ public void testParseNormalState() {
4444

4545
@Test
4646
public void testParseSlotBeingMigrated() {
47-
String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :0 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]";
47+
String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :7379 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]";
4848
HostAndPort current = new HostAndPort("localhost", 7379);
4949
ClusterNodeInformation clusterNodeInfo = parser
5050
.parse(nodeInfo, current);

0 commit comments

Comments
 (0)