Skip to content

Commit 1dbf2ff

Browse files
committed
Call hstrlen on JedisCluster.
We now call hstrlen on the Cluster client instead of using our execute(…) fallback and determining the correct cluster node ourselves. Closes #2392
1 parent 2ca0c43 commit 1dbf2ff

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/main/java/org/springframework/data/redis/connection/RedisHashCommands.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,14 @@ public interface RedisHashCommands {
237237
Cursor<Map.Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options);
238238

239239
/**
240-
* Returns the length of the value associated with {@code field} in the hash stored at {@code key}. If the key or the
241-
* field do not exist, {@code 0} is returned.
240+
* Returns the length of the value associated with {@code field} in the hash stored at {@code key}. If the {@code key}
241+
* or the {@code field} do not exist, {@code 0} is returned.
242242
*
243243
* @param key must not be {@literal null}.
244244
* @param field must not be {@literal null}.
245245
* @return {@literal null} when used in pipeline / transaction.
246246
* @since 2.1
247+
* @see <a href="https://redis.io/commands/hstrlen">Redis Documentation: HSTRLEN</a>
247248
*/
248249
@Nullable
249250
Long hStrLen(byte[] key, byte[] field);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import redis.clients.jedis.ScanParams;
1919

2020
import java.util.ArrayList;
21-
import java.util.Collections;
2221
import java.util.List;
2322
import java.util.Map;
2423
import java.util.Map.Entry;
@@ -364,7 +363,11 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(long cursorId, ScanOptions
364363
@Nullable
365364
@Override
366365
public Long hStrLen(byte[] key, byte[] field) {
367-
return Long.class.cast(connection.execute("HSTRLEN", key, Collections.singleton(field)));
366+
367+
Assert.notNull(key, "Key must not be null");
368+
Assert.notNull(field, "Field must not be null");
369+
370+
return connection.getCluster().hstrlen(key, field);
368371
}
369372

370373
private DataAccessException convertJedisAccessException(Exception ex) {

0 commit comments

Comments
 (0)