summaryrefslogtreecommitdiff
path: root/redis/lock.py
diff options
context:
space:
mode:
authorRobert Kopaczewski <rk@23doors.com>2014-12-10 04:21:10 +0100
committerRobert Kopaczewski <rk@23doors.com>2014-12-10 04:21:10 +0100
commit08d37bd490014ebbba9f6c60e1f149e7255b69b4 (patch)
treeb5e54b4b0e4a9455aa193b4ddf60c00a387f5aa5 /redis/lock.py
parent2139d817f58fbecc1b708d488af5ba514f3329cd (diff)
downloadredis-py-08d37bd490014ebbba9f6c60e1f149e7255b69b4.tar.gz
Fix lua locking
Diffstat (limited to 'redis/lock.py')
-rw-r--r--redis/lock.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/redis/lock.py b/redis/lock.py
index a4412ea..fc94ed5 100644
--- a/redis/lock.py
+++ b/redis/lock.py
@@ -123,7 +123,7 @@ class Lock(object):
timeout = int(self.timeout * 1000)
else:
timeout = None
- if redis.set(self.name, token, nx=True, px=timeout):
+ if self.redis.set(self.name, token, nx=True, px=timeout):
return True
return False
@@ -198,15 +198,11 @@ class LuaLock(Lock):
# ARGV[2] - timeout in milliseconds
# return 1 if lock was acquired, otherwise 0
LUA_ACQUIRE_SCRIPT = """
- local args
-
+ local args = {}
if ARGV[2] ~= '' then
- args = {'set', KEYS[1], ARGV[1], 'nx'}
- else
- args = {'set', KEYS[1], ARGV[1], 'nx', 'px', ARGV[2]}
+ args = {'px', ARGV[2]}
end
-
- if redis.call(unpack(args)) == 1 then
+ if redis.call('set', KEYS[1], ARGV[1], 'nx', unpack(args)) then
return 1
end
return 0