RedisReactiveCommands calls OnComplete when the key is not found

53 views
Skip to first unread message

Pete Jones

unread,
May 29, 2020, 11:09:07 AM5/29/20
to lettuce-redis-client-users
I am using RedisReactiveCommands to get a value for a key like this:

RedisReactiveCommands<String, String> reactiveCommands = connection.reactive();
Mono<String>  keyValue = reactiveCommands.get("auth");

keyValue.map((val) -> {
                  // my return value handling code here
                  // which should handle the case where key is not found
            }
)

If the the key 'auth' does not exist, the Mono directly calls OnComplete without calling OnNext with a null value. However I wish to handle the key does not exist case as part of the business logic. 
How can I do that? According to the documentation, it should call OnNext with a Null value?

Max Grigoriev

unread,
May 29, 2020, 11:23:26 AM5/29/20
to lettuce-redis-client-users
You can use
Mono#switchIfEmpty
or
Mono#defaultIfEmpty
Reply all
Reply to author
Forward
0 new messages