Skip to content

Instantly share code, notes, and snippets.

@chaizhenhua
Last active April 19, 2017 20:31
Show Gist options
  • Select an option

  • Save chaizhenhua/8370206 to your computer and use it in GitHub Desktop.

Select an option

Save chaizhenhua/8370206 to your computer and use it in GitHub Desktop.
redis lua script for reliable async task framwork
-- lremzadd source destination member score [member score ...]
local i = 3
local ret = 0
while KEYS[i] do
local x = redis.call("LREM", KEYS[1], 1, KEYS[i])
if x > 0 then
ret = ret + redis.call("ZADD", KEYS[2], KEYS[i+1], KEYS[i])
end
i = i + 2
end
return ret
-- sremzadd source destination member score [member score ...]
local i = 3
local ret = 0
while KEYS[i] do
local x = redis.call("SREM", KEYS[1], 1, KEYS[i])
if x > 0 then
ret = ret + redis.call("ZADD", KEYS[2], KEYS[i+1], KEYS[i])
end
i = i + 2
end
return ret
-- zremlpush source destination member [member ...]
local i = 3
local ret = 0
while KEYS[i] do
local n = redis.call("ZREM", KEYS[1], KEYS[i])
if n > 0 then
redis.call("LPUSH", KEYS[2], KEYS[i])
ret = ret + 1
end
i = i + 1
end
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment