I'm using spring boot webflux
+ project reactor
+ lettuce
for connecting and querying Redis in a non blocking way.
I have configured the ReactiveRedisTemplate
with LettuceConnectionFactory
. The spring documentation states that the only way to use pipeline with ReactiveRedisTemplate
is to use the execute(<RedisCallback>)
method. In non-reactive RedisTemplate
, I see that there is an executePipelined(<RedisCallback>)
method which opens/closes a pipeline before executing the callback. But in case of ReactiveRedisTemplate.execute
method, it uses a LettuceReactiveRedisConnection
and neither Spring ReactiveRedisConnection
nor Lettuce
has no reference to pipeline.
So my question is, is it possible to pipleline your commands when using Spring ReactiveRedisTemplate
+ ReactiveLettuceConnection
?
I also noticed that using ReactiveRedisTemplate.execute
with a RedisCallback
that has multiple Redis commands executes slower than just calling commands individually.
Sample code for pipleline with ReactiveRedisTemplate:
reactiveRedisTemplate.execute(connection -> keys.flatMap(key ->
connection.hashCommands()
.hGetAll(ByteBuffer.wrap(key.getBytes()))))
.map(Map.Entry::getValue)
.map(ByteUtils::getBytes)
.map(b -> {
try {
return mapper.readValue(b, Value.class);
} catch (IOException e1) {
return null;
}
})
.collectList();
Code without pipeline:
keys.flatMap(key -> reactiveRedisTemplate.opsForHash().entries(key))
.map(Map.Entry::getValue)
.cast(Value.class)
.collectList();
Thanks!