Skip to content

Commit dfc56a6

Browse files
committed
Fix Jedis cluster connection lookup for IPv6 hosts.
We previously used our own mechanism to Render Host and Port causing that IPv6 addresses were enclosed in brackets. Now we've aligned with Jedis' keying by using HostAndPort that just concatenates the host and port part. Closes #3015
1 parent 131e765 commit dfc56a6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import redis.clients.jedis.HostAndPort;
2121
import redis.clients.jedis.Jedis;
2222
import redis.clients.jedis.JedisCluster;
23+
import redis.clients.jedis.JedisClusterInfoCache;
24+
import redis.clients.jedis.Protocol;
2325
import redis.clients.jedis.providers.ClusterConnectionProvider;
2426

2527
import java.time.Duration;
@@ -764,11 +766,16 @@ public Jedis getResourceForSpecificNode(RedisClusterNode node) {
764766
throw new DataAccessResourceFailureException(String.format("Node %s is unknown to cluster", node));
765767
}
766768

769+
@Nullable
767770
private ConnectionPool getResourcePoolForSpecificNode(RedisClusterNode node) {
768771

769772
Map<String, ConnectionPool> clusterNodes = cluster.getClusterNodes();
770-
if (clusterNodes.containsKey(node.asString())) {
771-
return clusterNodes.get(node.asString());
773+
HostAndPort hap = new HostAndPort(node.getHost(),
774+
node.getPort() == null ? Protocol.DEFAULT_PORT : node.getPort());
775+
String key = JedisClusterInfoCache.getNodeKey(hap);
776+
777+
if (clusterNodes.containsKey(key)) {
778+
return clusterNodes.get(key);
772779
}
773780

774781
return null;

0 commit comments

Comments
 (0)