From fcefc53783a19dda0974a4b297d9ef6228f77249 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 73b749f421..d2896b75c2 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 8cf7c22e22..56174d1fa5 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 @@ -18,7 +18,6 @@ import redis.clients.jedis.ScanParams; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -364,7 +363,11 @@ protected ScanIteration> doScan(long cursorId, ScanOptions @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) {