robust-redis-lock 0.4.2 → 0.4.3
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 +10 -8
- data/lib/robust-redis-lock/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87fa0ff80f974931ac04891862c75421405bc71
|
4
|
+
data.tar.gz: e5eca4757e7d19d6cfd806a276669792ca1f225e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d52484eb62093f86949edede7e329ea6b7756e59f66c5b8189959d9f30354831f6fc9cc007aa929d447f1773d087da2b1a1ef108bc04e5f2aad324a217f38e0
|
7
|
+
data.tar.gz: e4f5c0cfebb70f1ac82ef638a89e80f3aed369bde4e912a06c19780e6d409660cac4acd2d193b8173ca8c5f8ca2184c79d504aaf9f963ce1f19a6e6acc4ed965
|
data/lib/redis-lock.rb
CHANGED
@@ -96,7 +96,7 @@ class Redis::Lock
|
|
96
96
|
|
97
97
|
local prev_expires_at = tonumber(redis.call('hget', key, 'expires_at'))
|
98
98
|
if prev_expires_at and prev_expires_at > now then
|
99
|
-
return {'locked', nil}
|
99
|
+
return {'locked', nil, nil}
|
100
100
|
end
|
101
101
|
|
102
102
|
local next_token = redis.call('incr', token_key)
|
@@ -104,23 +104,25 @@ class Redis::Lock
|
|
104
104
|
redis.call('hset', key, 'expires_at', expires_at)
|
105
105
|
redis.call('hset', key, 'token', next_token)
|
106
106
|
redis.call('zadd', key_group, expires_at, key)
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
|
108
|
+
local prev_data = redis.call('hget', key, 'data')
|
109
|
+
redis.call('hset', key, 'data', data)
|
110
110
|
|
111
111
|
if prev_expires_at then
|
112
|
-
return {'recovered', next_token}
|
112
|
+
return {'recovered', next_token, prev_data}
|
113
113
|
else
|
114
|
-
return {'acquired', next_token}
|
114
|
+
return {'acquired', next_token, nil}
|
115
115
|
end
|
116
116
|
LUA
|
117
|
-
result, token = @@lock_script.eval(@redis, :keys => [@key, @key_group_key], :argv => [now.to_i, now.to_i + @expire, @serializer.dump(data)])
|
117
|
+
result, token, prev_data = @@lock_script.eval(@redis, :keys => [@key, @key_group_key], :argv => [now.to_i, now.to_i + @expire, @serializer.dump(@data)])
|
118
118
|
|
119
119
|
@token = token if token
|
120
120
|
|
121
121
|
case result
|
122
122
|
when 'locked' then return false
|
123
|
-
when 'recovered'
|
123
|
+
when 'recovered'
|
124
|
+
prev_data = @serializer.load(prev_data) if prev_data
|
125
|
+
return prev_data || :recovered
|
124
126
|
when 'acquired' then return true
|
125
127
|
end
|
126
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robust-redis-lock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kareem Kouddous
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|