ReactiveRedisTemplate does have an "execute" method similar to RedisTemplate but with different signatures. Sample code to execute pipeline commands using both the templates
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.testng.annotations.Test;
public class RedisPipeline {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private ReactiveRedisTemplate<String, String> reactiveRedisTemplate;
@Test
public void test() {
final List<Object> usingRedisTemplate = this.redisTemplate.executePipelined((RedisCallback<Object>)connection -> {
for (int i = 0; i < 5; i++) {
connection.listCommands().rPop("pipeline-list".getBytes());
}
return null;
});
final List<Object> usingReactiveRedisTemplate = this.reactiveRedisTemplate.execute(connection -> {
for (int i = 0; i < 5; i++) {
connection.listCommands().rPop(toByteBuffer("pipeline-list")).block();
}
return null;
}).collectList().block();
}
private ByteBuffer toByteBuffer(final String input) {
final ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(input);
final byte[] byteArray = new byte[byteBuffer.remaining()];
byteBuffer.get(byteArray);
return byteBuffer;
}