From 7d34afbcaa9f9060344c6969bf1ba047fd15974d Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 31 Aug 2022 10:09:43 +0200 Subject: [PATCH] Call `hstrlen` on `JedisCluster`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now call hstrlen on the Cluster client instead of using our execute(…) fallback and determining the correct cluster node ourselves. Closes #2392 --- .../data/redis/connection/RedisHashCommands.java | 5 +++-- .../redis/connection/jedis/JedisClusterHashCommands.java | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/RedisHashCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisHashCommands.java index 73b749f42..d2896b75c 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisHashCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisHashCommands.java @@ -237,13 +237,14 @@ public interface RedisHashCommands { Cursor> hScan(byte[] key, ScanOptions options); /** - * Returns the length of the value associated with {@code field} in the hash stored at {@code key}. If the key or the - * field do not exist, {@code 0} is returned. + * Returns the length of the value associated with {@code field} in the hash stored at {@code key}. If the {@code key} + * or the {@code field} do not exist, {@code 0} is returned. * * @param key must not be {@literal null}. * @param field must not be {@literal null}. * @return {@literal null} when used in pipeline / transaction. * @since 2.1 + * @see Redis Documentation: HSTRLEN */ @Nullable Long hStrLen(byte[] key, byte[] field); diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterHashCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterHashCommands.java index d6d0f9de8..b33eab324 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterHashCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterHashCommands.java @@ -19,7 +19,6 @@ import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -289,7 +288,11 @@ class JedisClusterHashCommands implements RedisHashCommands { @Nullable @Override public Long hStrLen(byte[] key, byte[] field) { - return Long.class.cast(connection.execute("HSTRLEN", key, Collections.singleton(field))); + + Assert.notNull(key, "Key must not be null"); + Assert.notNull(field, "Field must not be null"); + + return connection.getCluster().hstrlen(key, field); } private DataAccessException convertJedisAccessException(Exception ex) {