mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 02:08:12 +01:00
Add a cluster-backed message cache.
This commit is contained in:
committed by
Jon Chambers
parent
639898ec07
commit
6fc1b4c6c0
@@ -1,7 +1,16 @@
|
||||
-- keys: queue_key [1], queue_metadata_key [2], queue_total_index [3]
|
||||
-- argv: message [1], current_time [2], sender (possibly null) [3], guid [4]
|
||||
-- argv: message [1], current_time [2], sender (possibly null) [3], guid [4], messageId (possibly null) [5]
|
||||
|
||||
local messageId
|
||||
|
||||
if ARGV[5] ~= nil then
|
||||
-- TODO: Remove this branch (and ARGV[5]) once the migration to a clustered message cache is finished
|
||||
messageId = tonumber(ARGV[5])
|
||||
redis.call("HSET", KEYS[2], "counter", messageId)
|
||||
else
|
||||
messageId = redis.call("HINCRBY", KEYS[2], "counter", 1)
|
||||
end
|
||||
|
||||
local messageId = redis.call("HINCRBY", KEYS[2], "counter", 1)
|
||||
redis.call("ZADD", KEYS[1], "NX", messageId, ARGV[1])
|
||||
|
||||
if ARGV[3] ~= "nil" then
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
-- keys: queue_key, queue_metadata_key, queue_index
|
||||
-- argv: index_to_remove
|
||||
|
||||
local envelope = redis.call("ZRANGEBYSCORE", KEYS[1], ARGV[1], ARGV[1], "LIMIT", 0, 1)
|
||||
local removedCount = redis.call("ZREMRANGEBYSCORE", KEYS[1], ARGV[1], ARGV[1])
|
||||
local senderIndex = redis.call("HGET", KEYS[2], ARGV[1])
|
||||
local guidIndex = redis.call("HGET", KEYS[2], ARGV[1] .. "guid")
|
||||
@@ -19,4 +20,8 @@ if (redis.call("ZCARD", KEYS[1]) == 0) then
|
||||
redis.call("ZREM", KEYS[3], KEYS[1])
|
||||
end
|
||||
|
||||
return removedCount > 0
|
||||
if envelope and next(envelope) then
|
||||
return envelope[1]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user