Skip to content

Commit 7366fc1

Browse files
committed
Attempted fix for #1229 - multiple entries in node list for same host
1 parent 833308c commit 7366fc1

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ private void initializeSlotsCache(Set<HostAndPort> startNodes, GenericObjectPool
4646
}
4747
}
4848
}
49-
50-
for (HostAndPort node : startNodes) {
51-
cache.setNodeIfNotExist(node);
52-
}
5349
}
5450

5551
public void renewSlotCache() {

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,35 @@ public void testReturnConnectionOnRedirection() {
538538
jc.get("e");
539539
}
540540

541+
@Test
542+
public void testLocalhostNodeNotAddedWhen127Present() {
543+
HostAndPort localhost = new HostAndPort("localhost", 7379);
544+
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
545+
// cluster node is defined as 127.0.0.1; adding localhost should work,
546+
// but shouldn't show up.
547+
jedisClusterNode.add(localhost);
548+
JedisPoolConfig config = new JedisPoolConfig();
549+
config.setMaxTotal(1);
550+
JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, config);
551+
Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
552+
assertEquals(3, clusterNodes.size());
553+
assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(localhost)));
554+
}
555+
556+
@Test
557+
public void testInvalidStartNodeNotAdded() {
558+
HostAndPort invalidHost = new HostAndPort("not-a-real-host", 7379);
559+
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
560+
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
561+
jedisClusterNode.add(invalidHost);
562+
JedisPoolConfig config = new JedisPoolConfig();
563+
config.setMaxTotal(1);
564+
JedisCluster jc = new JedisCluster(jedisClusterNode, 0, 2, config);
565+
Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
566+
assertEquals(3, clusterNodes.size());
567+
assertFalse(clusterNodes.containsKey(JedisClusterInfoCache.getNodeKey(invalidHost)));
568+
}
569+
541570
private static String getNodeServingSlotRange(String infoOutput) {
542571
// f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0
543572
// 1394372400827 0 connected 5461-10922

0 commit comments

Comments
 (0)