Last active
April 19, 2017 20:31
-
-
Save chaizhenhua/8370206 to your computer and use it in GitHub Desktop.
redis lua script for reliable async task framwork
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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