diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java index 6449c2a07..015e58fcb 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommands.java @@ -37,6 +37,7 @@ import org.springframework.util.Assert; /** * @author Christoph Strobl * @author Mark Paluch + * @author Jiahe Cai * @since 2.0 */ class LettuceReactiveStringCommands implements ReactiveStringCommands { @@ -93,7 +94,9 @@ class LettuceReactiveStringCommands implements ReactiveStringCommands { Mono mono = args != null ? cmd.set(command.getKey(), command.getValue(), args) : cmd.set(command.getKey(), command.getValue()); - return mono.map(LettuceConverters::stringToBoolean).map((value) -> new BooleanResponse<>(command, value)); + return mono.map(LettuceConverters::stringToBoolean) + .map(value -> new BooleanResponse<>(command, value)) + .switchIfEmpty(Mono.just(new BooleanResponse<>(command, Boolean.FALSE))); })); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java index 463923de6..7d558e4a8 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java @@ -45,6 +45,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * * @author Mark Paluch * @author Christoph Strobl + * @author Jiahe Cai */ @RunWith(Parameterized.class) @SuppressWarnings("unchecked") @@ -131,7 +132,7 @@ public class DefaultReactiveValueOperationsIntegrationTests { StepVerifier.create(valueOperations.setIfAbsent(key, value)).expectNext(true).verifyComplete(); - StepVerifier.create(valueOperations.setIfAbsent(key, value)).verifyComplete(); + StepVerifier.create(valueOperations.setIfAbsent(key, value)).expectNext(false).verifyComplete(); } @Test // DATAREDIS-602 @@ -141,7 +142,7 @@ public class DefaultReactiveValueOperationsIntegrationTests { V value = valueFactory.instance(); V laterValue = valueFactory.instance(); - StepVerifier.create(valueOperations.setIfPresent(key, value)).verifyComplete(); + StepVerifier.create(valueOperations.setIfPresent(key, value)).expectNext(false).verifyComplete(); StepVerifier.create(valueOperations.set(key, value)).expectNext(true).verifyComplete();