DATAREDIS-1161 - Avoid returning null in ReactiveHashCommands.hGet(…).

We now use flatMapIterable(…).next() to return the first value from the hash. Previously, if the returned list was empty, we could return a null value in the mapping function which might have caused an exception.

Original Pull Request: #538
This commit is contained in:
Mark Paluch
2020-06-08 16:02:30 +02:00
committed by Christoph Strobl
parent ef133f8679
commit e6410fea51

View File

@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.reactivestreams.Publisher;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -282,7 +283,7 @@ 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)).map(val -> val.isEmpty() ? null : val.iterator().next());
return hMGet(key, Collections.singletonList(field)).flatMapIterable(Function.identity()).next();
}
/**