您可以将逻辑包装到Lua脚本中,以确保客户端获得
N顺序项目。
local key = KEYS[1]local N = tonumber(ARGV[1])local size = redis.call("llen", key)if size < N then return {} end -- ensure that there're at least N itemslocal res = {}for i = 1, N do -- get N items in a transaction res[i] = redis.call("lpop", key);endreturn res


