From e6410fea5155ef75d4441220f466e67a87c48769 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 8 Jun 2020 16:02:30 +0200 Subject: [PATCH] =?UTF-8?q?DATAREDIS-1161=20-=20Avoid=20returning=20null?= =?UTF-8?q?=20in=20ReactiveHashCommands.hGet(=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../data/redis/connection/ReactiveHashCommands.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java index 8d1140515..27877045a 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java @@ -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 Redis Documentation: HGET */ default Mono 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(); } /**