Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @author Mark Paluch
* @author Christoph Strobl
* @author John Blum
* @author Jewoo Shin
* @since 2.0
*/
class DefaultReactiveHashOperations<H, HK, HV> implements ReactiveHashOperations<H, HK, HV> {
Expand Down Expand Up @@ -215,6 +216,15 @@ public Flux<HK> keys(H key) {
.map(this::readRequiredHashKey));
}

@Override
public Mono<Long> lengthOfValue(H key, HK hashKey) {

Assert.notNull(key, "Key must not be null");
Assert.notNull(hashKey, "Hash key must not be null");

return createMono(hashCommands -> hashCommands.hStrLen(rawKey(key), rawHashKey(hashKey)));
}

@Override
public Mono<Long> size(H key) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @author Mark Paluch
* @author Christoph Strobl
* @author Viktoriya Kutsarova
* @author Jewoo Shin
* @since 2.0
*/
public interface ReactiveHashOperations<H, HK, HV> {
Expand Down Expand Up @@ -200,6 +201,18 @@ Mono<Boolean> putAndExpire(H key, Map<? extends HK, ? extends HV> map,
*/
Flux<HK> keys(H key);

/**
* Returns the length of the value associated with {@code hashKey}. If either the {@code key} or the {@code hashKey}
* do not exist, {@code 0} is emitted.
*
* @param key must not be {@literal null}.
* @param hashKey must not be {@literal null}.
* @return {@link Mono} emitting the length of the value associated with {@code hashKey}.
* @since 4.2
* @see <a href="https://redis.io/commands/hstrlen">Redis Documentation: HSTRLEN</a>
*/
Mono<Long> lengthOfValue(H key, HK hashKey);

/**
* Get size of hash at {@code key}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Jewoo Shin
*/
@ParameterizedClass
@MethodSource("testParams")
Expand Down Expand Up @@ -364,6 +365,26 @@ void keys() {
.verifyComplete();
}

@Test // GH-3376
void lengthOfValue() {

assumeThat(hashValueFactory instanceof StringObjectFactory).isTrue();

K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
HV hashvalue1 = hashValueFactory.instance();

HK hashkey2 = hashKeyFactory.instance();
HV hashvalue2 = hashValueFactory.instance();

putAll(key, hashkey1, hashvalue1, hashkey2, hashvalue2);

hashOperations.lengthOfValue(key, hashkey1) //
.as(StepVerifier::create) //
.expectNext((long) hashvalue1.toString().length()) //
.verifyComplete();
}

@Test // DATAREDIS-602
void size() {

Expand Down
Loading