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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f2fa7e0d73f535b0954a4c2230d10c1210756c5
4
- data.tar.gz: 6ade50d147b687dbd9c5d05c073e396200bd34d9
3
+ metadata.gz: a87fa0ff80f974931ac04891862c75421405bc71
4
+ data.tar.gz: e5eca4757e7d19d6cfd806a276669792ca1f225e
5
5
  SHA512:
6
- metadata.gz: 3916b3b7333f21bd8aea9f56a019b61be216a5a4c54fd3a56ecfea874836a8d5049796a7fa895c0bfdc41ac166f5bd0efcd9012805bdefe09624f2959b6a893d
7
- data.tar.gz: 21963e31733c5b397bbf4696ad9ab382e2fdf21c271e4c528b4c8ea442fde15a19f939bf269c0ce25027e0c08b12aa5d5270216d167a2b2581c7b99d7f48bf4b
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
- if data then
108
- redis.call('hset', key, 'data', data)
109
- end
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' then return :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
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class Lock
3
- VERSION = '0.4.2'
3
+ VERSION = '0.4.3'
4
4
  end
5
5
  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.2
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-18 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis