From 5425d2efce48090284a4671f627ee5a541507489 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Wed, 8 Sep 2021 10:02:34 -0700 Subject: [PATCH] Hash keys locally rather than call cluster keyslot Changing the remaining commands in JedisClusterKeyCommands to use the topology's getKeyServingMasterNode to find the node of key, rather than calling connection.clusterGetNodeForKey. clusterGetNodeForKey was making a cluster keyslot call to the server to hash the key, rather than hashing it locally. Closes: #2156 --- .../redis/connection/jedis/JedisClusterKeyCommands.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java index 9965552e3c..a1515c66f7 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java @@ -54,6 +54,7 @@ * @author Christoph Strobl * @author Mark Paluch * @author ihaohong + * @author Dan Smith * @since 2.0 */ class JedisClusterKeyCommands implements RedisKeyCommands { @@ -512,7 +513,7 @@ public void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolea return JedisConverters.toString(this.connection.execute("RESTORE", key, Arrays.asList(JedisConverters.toBytes(ttlInMillis), serializedValue, JedisConverters.toBytes("REPLACE")))); - }, connection.clusterGetNodeForKey(key)); + }, connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)); } /* @@ -595,7 +596,7 @@ public ValueEncoding encodingOf(byte[] key) { return connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback) client -> client.objectEncoding(key), - connection.clusterGetNodeForKey(key)) + connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .mapValue(JedisConverters::toEncoding); } @@ -611,7 +612,7 @@ public Duration idletime(byte[] key) { return connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback) client -> client.objectIdletime(key), - connection.clusterGetNodeForKey(key)) + connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .mapValue(Converters::secondsToDuration); } @@ -627,7 +628,7 @@ public Long refcount(byte[] key) { return connection.getClusterCommandExecutor() .executeCommandOnSingleNode((JedisClusterCommandCallback) client -> client.objectRefcount(key), - connection.clusterGetNodeForKey(key)) + connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .getValue(); }