mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 00:38:02 +01:00
Break out into a multi-module project
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
-- keys: lock_key
|
||||
-- argv: lock_value
|
||||
|
||||
if redis.call("GET", KEYS[1]) == ARGV[1] then
|
||||
return redis.call("DEL", KEYS[1])
|
||||
else
|
||||
return 0
|
||||
end
|
||||
70
service/src/main/resources/lua/apn/get.lua
Normal file
70
service/src/main/resources/lua/apn/get.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
-- keys: pending (KEYS[1])
|
||||
-- argv: max_time (ARGV[1]), limit (ARGV[2])
|
||||
|
||||
local hgetall = function (key)
|
||||
local bulk = redis.call('HGETALL', key)
|
||||
local result = {}
|
||||
local nextkey
|
||||
for i, v in ipairs(bulk) do
|
||||
if i % 2 == 1 then
|
||||
nextkey = v
|
||||
else
|
||||
result[nextkey] = v
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local getNextInterval = function(interval)
|
||||
if interval < 20000 then
|
||||
return 20000
|
||||
end
|
||||
|
||||
if interval < 40000 then
|
||||
return 40000
|
||||
end
|
||||
|
||||
if interval < 80000 then
|
||||
return 80000
|
||||
end
|
||||
|
||||
if interval < 160000 then
|
||||
return 160000
|
||||
end
|
||||
|
||||
if interval < 600000 then
|
||||
return 600000
|
||||
end
|
||||
|
||||
if interval < 1800000 then
|
||||
return 1800000
|
||||
end
|
||||
|
||||
return 3600000
|
||||
end
|
||||
|
||||
|
||||
local results = redis.call("ZRANGEBYSCORE", KEYS[1], 0, ARGV[1], "LIMIT", 0, ARGV[2])
|
||||
local collated = {}
|
||||
|
||||
if results and next(results) then
|
||||
for i, name in ipairs(results) do
|
||||
local pending = hgetall(name)
|
||||
local lastInterval = pending["interval"]
|
||||
|
||||
if lastInterval == nil then
|
||||
lastInterval = 0
|
||||
end
|
||||
|
||||
local nextInterval = getNextInterval(tonumber(lastInterval))
|
||||
|
||||
redis.call("HSET", name, "interval", nextInterval)
|
||||
redis.call("ZADD", KEYS[1], tonumber(ARGV[1]) + nextInterval, name)
|
||||
|
||||
collated[i] = pending["account"] .. ":" .. pending["device"]
|
||||
end
|
||||
end
|
||||
|
||||
return collated
|
||||
|
||||
|
||||
9
service/src/main/resources/lua/apn/insert.lua
Normal file
9
service/src/main/resources/lua/apn/insert.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
-- keys: pending (KEYS[1]), user (KEYS[2])
|
||||
-- args: timestamp (ARGV[1]), interval (ARGV[2]), account (ARGV[3]), device (ARGV[4])
|
||||
|
||||
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])
|
||||
|
||||
redis.call("ZADD", KEYS[1], ARGV[1], KEYS[2])
|
||||
4
service/src/main/resources/lua/apn/remove.lua
Normal file
4
service/src/main/resources/lua/apn/remove.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
-- keys: queue KEYS[1], endpoint (KEYS[2])
|
||||
|
||||
redis.call("DEL", KEYS[2])
|
||||
return redis.call("ZREM", KEYS[1], KEYS[2])
|
||||
10
service/src/main/resources/lua/get_items.lua
Normal file
10
service/src/main/resources/lua/get_items.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
-- keys: queue_key, queue_locked_key
|
||||
-- argv: limit
|
||||
|
||||
local locked = redis.call("GET", KEYS[2])
|
||||
|
||||
if locked then
|
||||
return {}
|
||||
end
|
||||
|
||||
return redis.call("ZRANGE", KEYS[1], 0, ARGV[1], "WITHSCORES")
|
||||
10
service/src/main/resources/lua/get_queues_to_persist.lua
Normal file
10
service/src/main/resources/lua/get_queues_to_persist.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
-- keys: queue_total_index
|
||||
-- argv: max_time, limit
|
||||
|
||||
local results = redis.call("ZRANGEBYSCORE", KEYS[1], 0, ARGV[1], "LIMIT", 0, ARGV[2])
|
||||
|
||||
if results and next(results) then
|
||||
redis.call("ZREM", KEYS[1], unpack(results))
|
||||
end
|
||||
|
||||
return results
|
||||
23
service/src/main/resources/lua/insert_item.lua
Normal file
23
service/src/main/resources/lua/insert_item.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
-- keys: queue_key [1], queue_metadata_key [2], queue_total_index [3]
|
||||
-- argv: message [1], current_time [2], sender (possibly null) [3], guid [4]
|
||||
|
||||
local messageId = redis.call("HINCRBY", KEYS[2], "counter", 1)
|
||||
redis.call("ZADD", KEYS[1], "NX", messageId, ARGV[1])
|
||||
|
||||
if ARGV[3] ~= "nil" then
|
||||
redis.call("HSET", KEYS[2], ARGV[3], messageId)
|
||||
end
|
||||
|
||||
redis.call("HSET", KEYS[2], ARGV[4], messageId)
|
||||
|
||||
if ARGV[3] ~= "nil" then
|
||||
redis.call("HSET", KEYS[2], messageId, ARGV[3])
|
||||
end
|
||||
|
||||
redis.call("HSET", KEYS[2], messageId .. "guid", ARGV[4])
|
||||
|
||||
redis.call("EXPIRE", KEYS[1], 7776000)
|
||||
redis.call("EXPIRE", KEYS[2], 7776000)
|
||||
|
||||
redis.call("ZADD", KEYS[3], "NX", ARGV[2], KEYS[1])
|
||||
return messageId
|
||||
28
service/src/main/resources/lua/remove_item_by_guid.lua
Normal file
28
service/src/main/resources/lua/remove_item_by_guid.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
-- keys: queue_key, queue_metadata_key, queue_index
|
||||
-- argv: guid_to_remove
|
||||
|
||||
local messageId = redis.call("HGET", KEYS[2], ARGV[1])
|
||||
|
||||
if messageId then
|
||||
local envelope = redis.call("ZRANGEBYSCORE", KEYS[1], messageId, messageId, "LIMIT", 0, 1)
|
||||
local sender = redis.call("HGET", KEYS[2], messageId)
|
||||
|
||||
redis.call("ZREMRANGEBYSCORE", KEYS[1], messageId, messageId)
|
||||
redis.call("HDEL", KEYS[2], ARGV[1])
|
||||
redis.call("HDEL", KEYS[2], messageId .. "guid")
|
||||
|
||||
if sender then
|
||||
redis.call("HDEL", KEYS[2], sender)
|
||||
redis.call("HDEL", KEYS[2], messageId)
|
||||
end
|
||||
|
||||
if (redis.call("ZCARD", KEYS[1]) == 0) then
|
||||
redis.call("ZREM", KEYS[3], KEYS[1])
|
||||
end
|
||||
|
||||
if envelope and next(envelope) then
|
||||
return envelope[1]
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
22
service/src/main/resources/lua/remove_item_by_id.lua
Normal file
22
service/src/main/resources/lua/remove_item_by_id.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
-- keys: queue_key, queue_metadata_key, queue_index
|
||||
-- argv: index_to_remove
|
||||
|
||||
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")
|
||||
|
||||
if senderIndex then
|
||||
redis.call("HDEL", KEYS[2], senderIndex)
|
||||
redis.call("HDEL", KEYS[2], ARGV[1])
|
||||
end
|
||||
|
||||
if guidIndex then
|
||||
redis.call("HDEL", KEYS[2], guidIndex)
|
||||
redis.call("HDEL", KEYS[2], ARGV[1] .. "guid")
|
||||
end
|
||||
|
||||
if (redis.call("ZCARD", KEYS[1]) == 0) then
|
||||
redis.call("ZREM", KEYS[3], KEYS[1])
|
||||
end
|
||||
|
||||
return removedCount > 0
|
||||
28
service/src/main/resources/lua/remove_item_by_sender.lua
Normal file
28
service/src/main/resources/lua/remove_item_by_sender.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
-- keys: queue_key, queue_metadata_key, queue_index
|
||||
-- argv: sender_to_remove
|
||||
|
||||
local messageId = redis.call("HGET", KEYS[2], ARGV[1])
|
||||
|
||||
if messageId then
|
||||
local envelope = redis.call("ZRANGEBYSCORE", KEYS[1], messageId, messageId, "LIMIT", 0, 1)
|
||||
local guid = redis.call("HGET", KEYS[2], messageId .. "guid")
|
||||
|
||||
redis.call("ZREMRANGEBYSCORE", KEYS[1], messageId, messageId)
|
||||
redis.call("HDEL", KEYS[2], ARGV[1])
|
||||
redis.call("HDEL", KEYS[2], messageId)
|
||||
|
||||
if guid then
|
||||
redis.call("HDEL", KEYS[2], guid)
|
||||
redis.call("HDEL", KEYS[2], messageId .. "guid")
|
||||
end
|
||||
|
||||
if (redis.call("ZCARD", KEYS[1]) == 0) then
|
||||
redis.call("ZREM", KEYS[3], KEYS[1])
|
||||
end
|
||||
|
||||
if envelope and next(envelope) then
|
||||
return envelope[1]
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
5
service/src/main/resources/lua/remove_queue.lua
Normal file
5
service/src/main/resources/lua/remove_queue.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
-- keys: queue_key, queue_metadata_key, queue_index
|
||||
|
||||
redis.call("DEL", KEYS[1])
|
||||
redis.call("DEL", KEYS[2])
|
||||
redis.call("ZREM", KEYS[3], KEYS[1])
|
||||
Reference in New Issue
Block a user