robust-redis-lock 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis-lock.rb +8 -3
- data/lib/robust-redis-lock/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f2fa7e0d73f535b0954a4c2230d10c1210756c5
|
4
|
+
data.tar.gz: 6ade50d147b687dbd9c5d05c073e396200bd34d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3916b3b7333f21bd8aea9f56a019b61be216a5a4c54fd3a56ecfea874836a8d5049796a7fa895c0bfdc41ac166f5bd0efcd9012805bdefe09624f2959b6a893d
|
7
|
+
data.tar.gz: 21963e31733c5b397bbf4696ad9ab382e2fdf21c271e4c528b4c8ea442fde15a19f939bf269c0ce25027e0c08b12aa5d5270216d167a2b2581c7b99d7f48bf4b
|
data/lib/redis-lock.rb
CHANGED
@@ -77,7 +77,10 @@ class Redis::Lock
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def data
|
80
|
-
@data ||=
|
80
|
+
@data ||= begin
|
81
|
+
raw = @redis.hget(key, 'data')
|
82
|
+
@serializer.load(raw) if raw
|
83
|
+
end
|
81
84
|
end
|
82
85
|
|
83
86
|
def try_lock
|
@@ -100,8 +103,10 @@ class Redis::Lock
|
|
100
103
|
|
101
104
|
redis.call('hset', key, 'expires_at', expires_at)
|
102
105
|
redis.call('hset', key, 'token', next_token)
|
103
|
-
redis.call('hset', key, 'data', data)
|
104
106
|
redis.call('zadd', key_group, expires_at, key)
|
107
|
+
if data then
|
108
|
+
redis.call('hset', key, 'data', data)
|
109
|
+
end
|
105
110
|
|
106
111
|
if prev_expires_at then
|
107
112
|
return {'recovered', next_token}
|
@@ -109,7 +114,7 @@ class Redis::Lock
|
|
109
114
|
return {'acquired', next_token}
|
110
115
|
end
|
111
116
|
LUA
|
112
|
-
result, token = @@lock_script.eval(@redis, :keys => [@key, @key_group_key], :argv => [now.to_i, now.to_i + @expire, @serializer.dump(
|
117
|
+
result, token = @@lock_script.eval(@redis, :keys => [@key, @key_group_key], :argv => [now.to_i, now.to_i + @expire, @serializer.dump(data)])
|
113
118
|
|
114
119
|
@token = token if token
|
115
120
|
|