Skip to content

Commit 19b4249

Browse files
upthewaterspoutmp911de
authored andcommitted
Hash keys using Jedis 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 Original pull request: #2159.
1 parent d37341e commit 19b4249

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
/**
5454
* @author Christoph Strobl
5555
* @author Mark Paluch
56+
* @author Dan Smith
5657
* @since 2.0
5758
*/
5859
class JedisClusterKeyCommands implements RedisKeyCommands {
@@ -498,7 +499,7 @@ public void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolea
498499
return JedisConverters.toString(this.connection.execute("RESTORE", key,
499500
Arrays.asList(JedisConverters.toBytes(ttlInMillis), serializedValue, JedisConverters.toBytes("REPLACE"))));
500501

501-
}, connection.clusterGetNodeForKey(key));
502+
}, connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key));
502503
}
503504

504505
/*
@@ -581,7 +582,7 @@ public ValueEncoding encodingOf(byte[] key) {
581582

582583
return connection.getClusterCommandExecutor()
583584
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.objectEncoding(key),
584-
connection.clusterGetNodeForKey(key))
585+
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
585586
.mapValue(JedisConverters::toEncoding);
586587
}
587588

@@ -597,7 +598,7 @@ public Duration idletime(byte[] key) {
597598

598599
return connection.getClusterCommandExecutor()
599600
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectIdletime(key),
600-
connection.clusterGetNodeForKey(key))
601+
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
601602
.mapValue(Converters::secondsToDuration);
602603
}
603604

@@ -613,7 +614,7 @@ public Long refcount(byte[] key) {
613614

614615
return connection.getClusterCommandExecutor()
615616
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectRefcount(key),
616-
connection.clusterGetNodeForKey(key))
617+
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
617618
.getValue();
618619

619620
}

0 commit comments

Comments
 (0)