Skip to content

Commit

Permalink
Call hstrlen on JedisCluster.
Browse files Browse the repository at this point in the history
We now call hstrlen on the Cluster client instead of using our execute(…) fallback and determining the correct cluster node ourselves.

Closes #2392
  • Loading branch information
mp911de committed Aug 31, 2022
1 parent 492634a commit fcefc53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ public interface RedisHashCommands {
Cursor<Map.Entry<byte[], byte[]>> 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 <a href="https://redis.io/commands/hstrlen">Redis Documentation: HSTRLEN</a>
*/
@Nullable
Long hStrLen(byte[] key, byte[] field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -364,7 +363,11 @@ protected ScanIteration<Entry<byte[], byte[]>> 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) {
Expand Down

0 comments on commit fcefc53

Please sign in to comment.