DATAREDIS-779 - Emit false if a conditional ReactiveStringCommands.set(…) does not set a value.

We now emit false when SET XX/SET NX complete without setting the value because the condition was evaluated to not set the value. Previously, we did not emit a value as Redis responds null (nil). This behavior becomes visible through ReactiveValueOperations.set[ifPresent|ifAbsent](…) methods.

This is a breaking change in the sense that changes the character of ReactiveValueOperations.set[ifPresent|ifAbsent](…) from an optionally emitted element to always emit. Reactive sequences that currently resume operation with .switchIfEmpty(…) will no longer utilize the fallback publisher.

Original pull request: #317.
This commit is contained in:
Jiahe Cai (佳何 蔡)
2018-03-06 14:08:04 +08:00
committed by Mark Paluch
parent 1f6790b100
commit fe80804873
2 changed files with 7 additions and 3 deletions

View File

@@ -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<String> 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)));
}));
}