Shard push scheduling cache

This commit is contained in:
Jon Chambers
2021-01-19 15:50:12 -05:00
committed by GitHub
parent e600e9c583
commit 943a5d1036
7 changed files with 436 additions and 169 deletions

View File

@@ -1,5 +1,7 @@
-- keys: pending (KEYS[1])
-- argv: max_time (ARGV[1]), limit (ARGV[2])
local pendingNotificationQueue = KEYS[1]
local maxTime = ARGV[1]
local limit = ARGV[2]
local hgetall = function (key)
local bulk = redis.call('HGETALL', key)
@@ -44,7 +46,7 @@ local getNextInterval = function(interval)
end
local results = redis.call("ZRANGEBYSCORE", KEYS[1], 0, ARGV[1], "LIMIT", 0, ARGV[2])
local results = redis.call("ZRANGEBYSCORE", pendingNotificationQueue, 0, maxTime, "LIMIT", 0, limit)
local collated = {}
if results and next(results) then
@@ -59,12 +61,10 @@ if results and next(results) then
local nextInterval = getNextInterval(tonumber(lastInterval))
redis.call("HSET", name, "interval", nextInterval)
redis.call("ZADD", KEYS[1], tonumber(ARGV[1]) + nextInterval, name)
redis.call("ZADD", pendingNotificationQueue, tonumber(maxTime) + nextInterval, name)
collated[i] = pending["account"] .. ":" .. pending["device"]
end
end
return collated

View File

@@ -1,9 +1,14 @@
-- keys: pending (KEYS[1]), user (KEYS[2])
-- args: timestamp (ARGV[1]), interval (ARGV[2]), account (ARGV[3]), device (ARGV[4])
local pendingNotificationQueue = KEYS[1]
local endpoint = KEYS[2]
redis.call("HSET", KEYS[2], "created", ARGV[1])
redis.call("HSET", KEYS[2], "interval", ARGV[2])
redis.call("HSET", KEYS[2], "account", ARGV[3])
redis.call("HSET", KEYS[2], "device", ARGV[4])
local timestamp = ARGV[1]
local interval = ARGV[2]
local account = ARGV[3]
local deviceId = ARGV[4]
redis.call("ZADD", KEYS[1], ARGV[1], KEYS[2])
redis.call("HSET", endpoint, "created", timestamp)
redis.call("HSET", endpoint, "interval", interval)
redis.call("HSET", endpoint, "account", account)
redis.call("HSET", endpoint, "device", deviceId)
redis.call("ZADD", pendingNotificationQueue, timestamp, endpoint)

View File

@@ -1,4 +1,5 @@
-- keys: queue KEYS[1], endpoint (KEYS[2])
local pendingNotificationQueue = KEYS[1]
local endpoint = KEYS[2]
redis.call("DEL", KEYS[2])
return redis.call("ZREM", KEYS[1], KEYS[2])
redis.call("DEL", endpoint)
return redis.call("ZREM", pendingNotificationQueue, endpoint)