-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutbox_record_sent.lua
34 lines (27 loc) · 1.05 KB
/
outbox_record_sent.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local queuesKey, queueKey, readyKey, queueID, msgID = KEYS[1], KEYS[2], KEYS[3], ARGV[1], tonumber(ARGV[2])
local thisItem = redis.call("LINDEX", queueKey, 0)
if thisItem == false then
return {"empty"}
end
-- check that the id of the message we're removing matches the one we were given
local msg = cjson.decode(thisItem)
if msg["id"] ~= msgID then
return {"wrong-id", tostring(msg["id"])}
end
-- remove the message from the queue
redis.call("LTRIM", queueKey, 1, -1)
-- now check if there are any more messages in the queue
local nextItem = redis.call("LINDEX", queueKey, 0)
local hasMore = false
if nextItem == false then
-- nothing more in the queue for this chat so take it out of the master set
redis.call("ZREM", queuesKey, queueID)
else
-- update the score of this queue to the timestamp of its new oldest message
local msg = cjson.decode(nextItem)
redis.call("ZADD", queuesKey, msg["_ts"], queueID)
hasMore = true
end
-- put this chat back in the ready set
redis.call("SADD", readyKey, queueID)
return {"success", tostring(hasMore)}