0
votes

I know keys command should be avoided in Redis because it's an expensive opperation.

But what if I'm using reactive driver (Lettuce) in reactive programming (Spring Data Redis Reactive), where the keys returns a Flux? Would this still be a "problem"?

Obs.: this is not a real situation for me. I'm just trying to understand the correct behaviour, since I've just started with reactive stuff.

Thanks in advance.

1

1 Answers

1
votes

As described in the javadoc, scan is still preferable to keys even in reactive environment:

IMPORTANT: It is recommended to use ReactiveRedisOperations.scan() to iterate over the keyspace as ReactiveRedisOperations.keys(Object) is a non-interruptible and expensive Redis operation.

The problem with keys is not really on client side, it's rather on Redis side. That's why a reactive client doesn't really make a difference in this case. Although, scan is also better for reactive client because it can request new keys on demand respecting backpressure.

But you have a valid point, it's a bit confusing that keys returns Flux. Based on the semantic of the Redis command I'd rather expect a Mono<List> as return type.