0
@Autowired
    private StringRedisTemplate stringRedisTemplate; 

public List<Object> getDataFromRedis(String redisKey) {
        
            try {
                
                long numberOfEntriesToRead = 60000;
                return stringRedisTemplate.executePipelined(
                        (RedisConnection connection) -> {
                            StringRedisConnection stringRedisConn =(StringRedisConnection)connection;
                            for (int index = 0; index < numberOfEntriesToRead; index++) {
                                stringRedisConn.lPop(redisKey);
                            }
                            return null;
                        });
            }catch (RedisCommandInterruptedException e) {
                LOGGER.error("Interrupted EXCEPTION :::", e);
            }
        } 
    }

I have a method which reads redis content for given key. Now the problem is when my application server is stopped while this method is trying to fetch data from redis i am getting RedisCommandInterruptedException exception which results in loss of some data from redis. So how can i overcome this problem Any suggestions are appreciable.

ram m
  • 3
  • 4

1 Answers1

0

Pipelines are not atomic operations therefore there is no guarantee that all/none of the commands are executed when an exception happens.

You can use lua scripts or multi command to make run operations in a single transaction. You can read more about using multi in spring boot data redis in this SO thread and this site.

Adam N.
  • 98
  • 4