Skip to content

Commit 5d617ed

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 7735a03 commit 5d617ed

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
@@ -54,6 +54,7 @@
5454
* @author Christoph Strobl
5555
* @author Mark Paluch
5656
* @author ihaohong
57+
* @author Dan Smith
5758
* @since 2.0
5859
*/
5960
class JedisClusterKeyCommands implements RedisKeyCommands {
@@ -512,7 +513,7 @@ public void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolea
512513
return JedisConverters.toString(this.connection.execute("RESTORE", key,
513514
Arrays.asList(JedisConverters.toBytes(ttlInMillis), serializedValue, JedisConverters.toBytes("REPLACE"))));
514515

515-
}, connection.clusterGetNodeForKey(key));
516+
}, connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key));
516517
}
517518

518519
/*
@@ -595,7 +596,7 @@ public ValueEncoding encodingOf(byte[] key) {
595596

596597
return connection.getClusterCommandExecutor()
597598
.executeCommandOnSingleNode((JedisClusterCommandCallback<byte[]>) client -> client.objectEncoding(key),
598-
connection.clusterGetNodeForKey(key))
599+
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
599600
.mapValue(JedisConverters::toEncoding);
600601
}
601602

@@ -611,7 +612,7 @@ public Duration idletime(byte[] key) {
611612

612613
return connection.getClusterCommandExecutor()
613614
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectIdletime(key),
614-
connection.clusterGetNodeForKey(key))
615+
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
615616
.mapValue(Converters::secondsToDuration);
616617
}
617618

@@ -627,7 +628,7 @@ public Long refcount(byte[] key) {
627628

628629
return connection.getClusterCommandExecutor()
629630
.executeCommandOnSingleNode((JedisClusterCommandCallback<Long>) client -> client.objectRefcount(key),
630-
connection.clusterGetNodeForKey(key))
631+
connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key))
631632
.getValue();
632633

633634
}

0 commit comments

Comments
 (0)