-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6dd369
commit 2c01f23
Showing
7 changed files
with
99 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local lock_key = KEYS[1] | ||
local lock_value = ARGV[1] | ||
local lock_ttl = tonumber(ARGV[2]) | ||
local reentrant_key = lock_key .. ':count:' .. lock_value | ||
local reentrant_count = tonumber(redis.call('GET', reentrant_key) or '0') | ||
|
||
if reentrant_count > 0 then | ||
redis.call('INCR', reentrant_key) | ||
redis.call('EXPIRE', lock_key, lock_ttl) | ||
redis.call('EXPIRE', reentrant_key, lock_ttl) | ||
return "OK" | ||
end | ||
|
||
if redis.call('SET', lock_key, lock_value, 'NX', 'EX', lock_ttl) then | ||
redis.call('SET', reentrant_key, 1) | ||
redis.call('EXPIRE', reentrant_key, lock_ttl) | ||
return "OK" | ||
end | ||
|
||
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
local lock_key = KEYS[1] | ||
local lock_value = ARGV[1] | ||
local lock_ttl = tonumber(ARGV[2]) | ||
local reentrant_key = lock_key .. ':count:' .. lock_value | ||
local reentrant_count = tonumber(redis.call('GET', reentrant_key) or '0') | ||
|
||
if reentrant_count > 0 or redis.call('GET', lock_key) == lock_value then | ||
redis.call('EXPIRE', lock_key, lock_ttl) | ||
redis.call('EXPIRE', reentrant_key, lock_ttl) | ||
return "OK" | ||
end | ||
|
||
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local lock_key = KEYS[1] | ||
local lock_value = ARGV[1] | ||
local reentrant_key = lock_key .. ':count:' .. lock_value | ||
local reentrant_count = tonumber(redis.call('GET', reentrant_key) or '0') | ||
|
||
if reentrant_count > 1 then | ||
redis.call('DECR', reentrant_key) | ||
return "OK" | ||
elseif reentrant_count == 1 then | ||
redis.call('DEL', reentrant_key) | ||
redis.call('DEL', lock_key) | ||
return "OK" | ||
end | ||
|
||
if redis.call('GET', lock_key) == lock_value then | ||
redis.call('DEL', lock_key) | ||
return "OK" | ||
else | ||
return nil | ||
end |