Last active
April 19, 2017 21:03
-
-
Save yanatan16/6688052 to your computer and use it in GitHub Desktop.
recurring tasks in relyq/qb lua scripts
This file contains 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
-- KEYS:[zset], ARGV:[now] | |
-- the sorted set contains key / next pairs, where next is the next execution time | |
-- Find all upcoming tasks | |
-- Get their intervals and requeue them | |
local refs = redis.call("zrangebyscore", KEYS[1], 0, ARGV[1]) | |
for i,ref in pairs(refs) do | |
tref, int = string.match(ref, "([^|]*)|(\d+)") | |
redis.call("zincrby", KEYS[1], int, tref) | |
refs[i] = tref | |
end | |
return refs |
This file contains 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
-- KEYS:[zset], ARGV:[ref, now, interval] | |
-- the sorted set contains key / next pairs, where next is the next execution time | |
local ref, now, interval = unpack(ARGV) | |
redis.call("zadd", KEYS[1], now + interval, ref .. "|" .. interval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment