Return single-element list with empty value when ReactiveHashOperations.hMGet(…) for a single key returns no value.

We now return a list containing a single empty KeyValue element when ReactiveHashOperations.hMGet(…) called for a single key returns no value.

Previously, the code used onErrorReturn(…) which returned the wrong value and suppressed errors.

Closes #2210
This commit is contained in:
Mark Paluch
2021-12-10 09:54:19 +01:00
parent bae2eae4f9
commit 9a56c38e2c
3 changed files with 12 additions and 3 deletions

View File

@@ -283,7 +283,8 @@ public interface ReactiveHashCommands {
* @see <a href="https://redis.io/commands/hget">Redis Documentation: HGET</a>
*/
default Mono<ByteBuffer> hGet(ByteBuffer key, ByteBuffer field) {
return hMGet(key, Collections.singletonList(field)).flatMapIterable(Function.identity()).next();
return hMGet(key, Collections.singletonList(field)).filter(it -> !it.contains(null))
.flatMapIterable(Function.identity()).next();
}
/**

View File

@@ -107,7 +107,7 @@ class LettuceReactiveHashCommands implements ReactiveHashCommands {
if (command.getFields().size() == 1) {
ByteBuffer key = command.getFields().iterator().next();
result = cmd.hget(command.getKey(), key.duplicate()).map(value -> KeyValue.fromNullable(key, value))
.map(Collections::singletonList).onErrorReturn(Collections.emptyList());
.defaultIfEmpty(KeyValue.empty(key)).map(Collections::singletonList);
} else {
result = cmd.hmget(command.getKey(), command.getFields().stream().toArray(ByteBuffer[]::new)).collectList();
}