Skip to content

Commit

Permalink
Fix Jedis cluster connection lookup for IPv6 hosts.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mp911de committed Oct 10, 2024
1 parent 252c1ba commit 8d4aee7
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisClusterInfoCache;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.providers.ClusterConnectionProvider;

import java.time.Duration;
Expand Down Expand Up @@ -764,11 +766,16 @@ public Jedis getResourceForSpecificNode(RedisClusterNode node) {
throw new DataAccessResourceFailureException("Node %s is unknown to cluster".formatted(node));
}

@Nullable
private ConnectionPool getResourcePoolForSpecificNode(RedisClusterNode node) {

Map<String, ConnectionPool> clusterNodes = cluster.getClusterNodes();
if (clusterNodes.containsKey(node.asString())) {
return clusterNodes.get(node.asString());
HostAndPort hap = new HostAndPort(node.getHost(),
node.getPort() == null ? Protocol.DEFAULT_PORT : node.getPort());
String key = JedisClusterInfoCache.getNodeKey(hap);

if (clusterNodes.containsKey(key)) {
return clusterNodes.get(key);
}

return null;
Expand Down

0 comments on commit 8d4aee7

Please sign in to comment.