2

Pipeline support is available on RedisTemplate (RedisTemplate.executePipelined) But I couldn't find any equivalent option in ReactiveRedisTemplate to use pipeline or batch operations.

Kindly direct me to the right API or any alternative approaches.

spring-data-redis:2.7.5 (with lettuce)

1 Answer 1

0

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;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

It is not advised to transactions with reactive Redis - stackoverflow.com/a/56648264/1780700

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.