Skip to content

Commit 177ed83

Browse files
mp911dechristophstrobl
authored andcommitted
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
1 parent 8f98af1 commit 177ed83

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/org/springframework/data/redis/connection/ReactiveHashCommands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Collections;
2525
import java.util.List;
2626
import java.util.Map;
27+
import java.util.function.Function;
2728

2829
import org.reactivestreams.Publisher;
2930
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -282,7 +283,7 @@ public List<ByteBuffer> getFields() {
282283
* @see <a href="https://redis.io/commands/hget">Redis Documentation: HGET</a>
283284
*/
284285
default Mono<ByteBuffer> hGet(ByteBuffer key, ByteBuffer field) {
285-
return hMGet(key, Collections.singletonList(field)).map(val -> val.isEmpty() ? null : val.iterator().next());
286+
return hMGet(key, Collections.singletonList(field)).flatMapIterable(Function.identity()).next();
286287
}
287288

288289
/**

0 commit comments

Comments
 (0)