-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathunlock.lua
34 lines (29 loc) · 1.29 KB
/
unlock.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
local exists_key = KEYS[1]
local grabbed_key = KEYS[2]
local available_key = KEYS[3]
local version_key = KEYS[4]
local unique_keys = KEYS[5]
local unique_digest = KEYS[6] -- TODO: Legacy support (Remove in v6.1)
local token = ARGV[1]
local expiration = tonumber(ARGV[2])
redis.call('HDEL', grabbed_key, token)
redis.call('SREM', unique_keys, unique_digest)
if expiration then
redis.log(redis.LOG_DEBUG, "signal_locks.lua - expiring stale locks")
redis.call('SREM', unique_keys, unique_digest)
redis.call('EXPIRE', exists_key, expiration)
redis.call('EXPIRE', available_key, expiration)
redis.call('EXPIRE', version_key, expiration) -- TODO: Legacy support (Remove in v6.1)
redis.call('EXPIRE', unique_digest, expiration) -- TODO: Legacy support (Remove in v6.1)
else
redis.call('DEL', exists_key)
redis.call('SREM', unique_keys, unique_digest)
redis.call('DEL', grabbed_key)
redis.call('DEL', available_key)
redis.call('DEL', version_key) -- TODO: Legacy support (Remove in v6.1)
redis.call('DEL', 'uniquejobs') -- TODO: Old job hash, just drop the darn thing (Remove in v6.1)
redis.call('DEL', unique_digest) -- TODO: Legacy support (Remove in v6.1)
end
local count = redis.call('LPUSH', available_key, token)
redis.call('EXPIRE', available_key, 5)
return count