forked from xiaoxuxiansheng/redis_lock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua.go
More file actions
25 lines (23 loc) · 685 Bytes
/
lua.go
File metadata and controls
25 lines (23 loc) · 685 Bytes
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
package redis_lock
// LuaCheckAndDeleteDistributionLock 判断是否拥有分布式锁的归属权,是则删除
const LuaCheckAndDeleteDistributionLock = `
local lockerKey = KEYS[1]
local targetToken = ARGV[1]
local getToken = redis.call('get',lockerKey)
if (not getToken or getToken ~= targetToken) then
return 0
else
return redis.call('del',lockerKey)
end
`
const LuaCheckAndExpireDistributionLock = `
local lockerKey = KEYS[1]
local targetToken = ARGV[1]
local duration = ARGV[2]
local getToken = redis.call('get',lockerKey)
if (not getToken or getToken ~= targetToken) then
return 0
else
return redis.call('expire',lockerKey,duration)
end
`