-- to avoid the problem with unpack ("too many results to unpack") -- we can increase LUAI_MAXCSTACK in luaconf.h https://www.lua.org/source/5.1/luaconf.h.html -- or execute the command with using table.unpack (https://www.lua.org/manual/5.1/manual.html#pdf-table.unpack) in chunks by specific length -- table.merge - separated function to merge two tables -- size of args should be >4000 (chunk length) local executeRedisCommandInChunks = function (command, key, args) local results = {} local chunkResult = {} local args_len = #args -- chunk length (any positive value less then 8000) local chunk_len = 4000 if (string.len(key)>0) then -- for commands with one key like HMGET/HMSET for i = 1, args_len, chunk_len do chunkResult = redis.call(command, key, unpack(args, i, math.min(i + chunk_len - 1, args_len))) results = table.merge(results,chunkResult) end else -- for commands like DEL/MGET/MSET/etc for i = 1, args_len, chunk_len do chunkResult = redis.call(command, unpack(args, i, math.min(i + chunk_len - 1, args_len))) results = table.merge(results,chunkResult) end end return results end