Skip to content

Commit 7d34afb

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 eaef5da commit 7d34afb

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
@@ -19,7 +19,6 @@
1919
import redis.clients.jedis.resps.ScanResult;
2020

2121
import java.util.ArrayList;
22-
import java.util.Collections;
2322
import java.util.List;
2423
import java.util.Map;
2524
import java.util.Map.Entry;
@@ -289,7 +288,11 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(long cursorId, ScanOptions
289288
@Nullable
290289
@Override
291290
public Long hStrLen(byte[] key, byte[] field) {
292-
return Long.class.cast(connection.execute("HSTRLEN", key, Collections.singleton(field)));
291+
292+
Assert.notNull(key, "Key must not be null");
293+
Assert.notNull(field, "Field must not be null");
294+
295+
return connection.getCluster().hstrlen(key, field);
293296
}
294297

295298
private DataAccessException convertJedisAccessException(Exception ex) {

0 commit comments

Comments
 (0)