Skip to content

Commit

Permalink
Add support for HSTRLEN #117
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Aug 17, 2015
1 parent f912fbe commit 878552a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 90 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Commands
* Support geo commands in lettuce 3.3 #86
* Support NX|XX|CH|INCR options in ZADD #74
* Add support for COUNTKEYSINSLOT #107
* Add support for HSTRLEN #117

Fixes
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ public RedisFuture<Long> hlen(K key) {
return dispatch(commandBuilder.hlen(key));
}

@Override
public RedisFuture<Long> hstrlen(K key, K field) {
return dispatch(commandBuilder.hstrlen(key, field));
}

@Override
public RedisFuture<List<V>> hmget(K key, K... fields) {
return dispatch(commandBuilder.hmget(key, fields));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ public Command<K, V, Long> hlen(K key) {
return createCommand(HLEN, new IntegerOutput<K, V>(codec), key);
}

public Command<K, V, Long> hstrlen(K key, K field) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).addKey(field);
return createCommand(HSTRLEN, new IntegerOutput<K, V>(codec), args);
}

public Command<K, V, List<V>> hmget(K key, K... fields) {
assertNotEmpty(fields, "fields " + MUST_NOT_BE_EMPTY);

Expand Down
99 changes: 54 additions & 45 deletions src/main/java/com/lambdaworks/redis/RedisHashesAsyncConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,51 +145,6 @@ public interface RedisHashesAsyncConnection<K, V> {
*/
RedisFuture<String> hmset(K key, Map<K, V> map);

/**
* Set the string value of a hash field.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return RedisFuture&lt;Boolean&gt; integer-reply specifically:
*
* {@literal true} if {@code field} is a new field in the hash and {@code value} was set. {@literal false} if
* {@code field} already exists in the hash and the value was updated.
*/
RedisFuture<Boolean> hset(K key, K field, V value);

/**
* Set the value of a hash field, only if the field does not exist.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return RedisFuture&lt;Boolean&gt; integer-reply specifically:
*
* {@literal true} if {@code field} is a new field in the hash and {@code value} was set. {@literal false} if
* {@code field} already exists in the hash and no operation was performed.
*/
RedisFuture<Boolean> hsetnx(K key, K field, V value);

/**
* Get all the values in a hash.
*
* @param key the key
* @return RedisFuture&lt;List&lt;V&gt;&gt; array-reply list of values in the hash, or an empty list when {@code key} does
* not exist.
*/
RedisFuture<List<V>> hvals(K key);

/**
* Stream over all the values in a hash.
*
* @param channel the channel
* @param key the key
*
* @return RedisFuture&lt;Long&gt; count of the keys.
*/
RedisFuture<Long> hvals(ValueStreamingChannel<V> channel, K key);

/**
* Incrementally iterate hash fields and associated values.
*
Expand Down Expand Up @@ -265,4 +220,58 @@ public interface RedisHashesAsyncConnection<K, V> {
* @return RedisFuture&lt;StreamScanCursor&gt; scan cursor.
*/
RedisFuture<StreamScanCursor> hscan(KeyValueStreamingChannel<K, V> channel, K key, ScanCursor scanCursor);

/**
* Set the string value of a hash field.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return RedisFuture&lt;Boolean&gt; integer-reply specifically:
*
* {@literal true} if {@code field} is a new field in the hash and {@code value} was set. {@literal false} if
* {@code field} already exists in the hash and the value was updated.
*/
RedisFuture<Boolean> hset(K key, K field, V value);

/**
* Set the value of a hash field, only if the field does not exist.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return RedisFuture&lt;Boolean&gt; integer-reply specifically:
*
* {@code 1} if {@code field} is a new field in the hash and {@code value} was set. {@code 0} if {@code field}
* already exists in the hash and no operation was performed.
*/
RedisFuture<Boolean> hsetnx(K key, K field, V value);

/**
* Get the string length of the field value in a hash.
*
* @param key the key
* @return RedisFuture&lt;Long&gt; integer-reply the string length of the {@code field} value, or {@code 0} when
* {@code field} is not present in the hash or {@code key} does not exist at all.
*/
RedisFuture<Long> hstrlen(K key, K field);

/**
* Get all the values in a hash.
*
* @param key the key
* @return RedisFuture&lt;List&lt;V&gt;&gt; array-reply list of values in the hash, or an empty list when {@code key} does
* not exist.
*/
RedisFuture<List<V>> hvals(K key);

/**
* Stream over all the values in a hash.
*
* @param channel streaming channel that receives a call for every value
* @param key the key
*
* @return RedisFuture&lt;Long&gt; count of the keys.
*/
RedisFuture<Long> hvals(ValueStreamingChannel<V> channel, K key);
}
97 changes: 53 additions & 44 deletions src/main/java/com/lambdaworks/redis/RedisHashesConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,50 +143,6 @@ public interface RedisHashesConnection<K, V> {
*/
String hmset(K key, Map<K, V> map);

/**
* Set the string value of a hash field.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return Boolean integer-reply specifically:
*
* {@literal true} if {@code field} is a new field in the hash and {@code value} was set. {@literal false} if
* {@code field} already exists in the hash and the value was updated.
*/
Boolean hset(K key, K field, V value);

/**
* Set the value of a hash field, only if the field does not exist.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return Boolean integer-reply specifically:
*
* {@code 1} if {@code field} is a new field in the hash and {@code value} was set. {@code 0} if {@code field}
* already exists in the hash and no operation was performed.
*/
Boolean hsetnx(K key, K field, V value);

/**
* Get all the values in a hash.
*
* @param key the key
* @return List&lt;V&gt; array-reply list of values in the hash, or an empty list when {@code key} does not exist.
*/
List<V> hvals(K key);

/**
* Stream over all the values in a hash.
*
* @param channel streaming channel that receives a call for every value
* @param key the key
*
* @return Long count of the keys.
*/
Long hvals(ValueStreamingChannel<V> channel, K key);

/**
* Incrementally iterate hash fields and associated values.
*
Expand Down Expand Up @@ -262,4 +218,57 @@ public interface RedisHashesConnection<K, V> {
* @return StreamScanCursor scan cursor.
*/
StreamScanCursor hscan(KeyValueStreamingChannel<K, V> channel, K key, ScanCursor scanCursor);

/**
* Set the string value of a hash field.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return Boolean integer-reply specifically:
*
* {@literal true} if {@code field} is a new field in the hash and {@code value} was set. {@literal false} if
* {@code field} already exists in the hash and the value was updated.
*/
Boolean hset(K key, K field, V value);

/**
* Set the value of a hash field, only if the field does not exist.
*
* @param key the key
* @param field the field type: key
* @param value the value
* @return Boolean integer-reply specifically:
*
* {@code 1} if {@code field} is a new field in the hash and {@code value} was set. {@code 0} if {@code field}
* already exists in the hash and no operation was performed.
*/
Boolean hsetnx(K key, K field, V value);

/**
* Get the string length of the field value in a hash.
*
* @param key the key
* @return Long integer-reply the string length of the {@code field} value, or {@code 0} when {@code field} is not present
* in the hash or {@code key} does not exist at all.
*/
Long hstrlen(K key, K field);

/**
* Get all the values in a hash.
*
* @param key the key
* @return List&lt;V&gt; array-reply list of values in the hash, or an empty list when {@code key} does not exist.
*/
List<V> hvals(K key);

/**
* Stream over all the values in a hash.
*
* @param channel streaming channel that receives a call for every value
* @param key the key
*
* @return Long count of the keys.
*/
Long hvals(ValueStreamingChannel<V> channel, K key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum CommandType implements ProtocolKeyword {

// Hash

HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HINCRBYFLOAT, HKEYS, HLEN, HMGET, HMSET, HSET, HSETNX, HVALS, HSCAN,
HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HINCRBYFLOAT, HKEYS, HLEN, HSTRLEN, HMGET, HMSET, HSET, HSETNX, HVALS, HSCAN,

// Transaction

Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/lambdaworks/redis/HashCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ public void hlen() throws Exception {
assertThat((long) redis.hlen(key)).isEqualTo(1);
}

@Test
public void hstrlen() throws Exception {
assertThat((long) redis.hstrlen(key, "one")).isEqualTo(0);
redis.hset(key, "one", value);
assertThat((long) redis.hstrlen(key, "one")).isEqualTo(value.length());
}

@Test
public void hmget() throws Exception {
setupHmget();
Expand Down

0 comments on commit 878552a

Please sign in to comment.