diff --git a/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java b/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java index 5fa64dbafb..e3aae7d028 100644 --- a/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java +++ b/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java @@ -423,6 +423,10 @@ public boolean equals(Object o) { return false; } + if (uri != null ? !uri.equals(that.uri) : that.uri != null) { + return false; + } + return true; } diff --git a/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java b/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java index ff1c15cbe1..bdf55646cf 100644 --- a/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java +++ b/src/test/java/io/lettuce/core/cluster/models/partitions/RedisClusterNodeUnitTests.java @@ -56,6 +56,20 @@ void testEquality() { assertThat(node.hashCode()).isNotEqualTo(new RedisClusterNode()); } + @Test + void testEqualityWithSameNodeIdDifferentHost() { + + RedisClusterNode nodeOne = new RedisClusterNode(); + nodeOne.setNodeId("123"); + nodeOne.setUri(RedisURI.builder().withHost("127.0.0.1").build()); + + RedisClusterNode nodeTwo = new RedisClusterNode(); + nodeOne.setNodeId("123"); + nodeOne.setUri(RedisURI.builder().withHost("127.0.0.2").build()); + + assertThat(nodeOne).isNotEqualTo(nodeTwo); + } + @Test void testToString() {