0
 Pipeline pipeline = jedis.pipelined();
        long len = jedis.llen(table);
        List<String> tableKeys = jedis.lrange(table, (long) 0, len);
        for (String key : tableKeys) {
            pipeline.del(key);
            pipeline.lrem(table, 1, key);
        }
        pipeline.sync();
        tableKeys.clear();

I am running into a issue here, when the key set is large I am getting an out of memory error at jedis.llrange.

Is there a better way to handle this, may be run the lrange in batches or pipelining the lrange?

I am planning on using a LUA script, just wanted to know if this would work

local result = redis.call('lrange',KEYS[1],0,ARGV[1]-1)
for i,k in ipairs(result) do
    redis.call(β€˜del’,k)
    redis.call('ltrim',KEYS[1],1,k)
end
user160108
  • 930
  • 3
  • 8
  • 38

0 Answers0