robust-redis-lock 1.2.0 → 1.3.0

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: 3e91ccab46ae6e04e6927f8b36e49f42a730500b
4
- data.tar.gz: 5e13ddaa92cece6db205b083159176827cdb4ae0
3
+ metadata.gz: 8da8da8a1f759bf85402feeb3985aee0fdf917c6
4
+ data.tar.gz: 3c69f1a649c2d26b069db228980e0427bf8574dd
5
5
  SHA512:
6
- metadata.gz: 807017173ce61abce329aa966eac6f965390ff3e90026139efd93d302e47f3744af2e4b32da10989f0ce851535fe04753ed9df50e35c30a53173766527d2c634
7
- data.tar.gz: 4569677ed33d4c4473d480e51874191621f1184c075b92b7384f265ceefa0249a711802087f866fd801a45fa8d5874625456394cc5dd4f4eb61a088d8ef759a6
6
+ metadata.gz: 2235d3e0b9658712cd1a8ca17fc697f0ed7257fd3a70d5710183984a6850d213fb67b8e988946788f495a3c2cdf77b034e2757ec5f993dbdc1355d26eda3ea16
7
+ data.tar.gz: f9c0d7ee0acd79c40d10185a78fdcad8fa1531090202c79b2f6070a9a6333259802cc41d664fa3603a3bd7829741318a8d952eda5087c2b3b2097c3083fea5a1
@@ -144,6 +144,8 @@ class Redis::Lock
144
144
  end
145
145
 
146
146
  def try_unlock
147
+ raise NotLocked.new('unlock', self) unless @token
148
+
147
149
  # Since it's possible that the operations in the critical section took a long time,
148
150
  # we can't just simply release the lock. The unlock method checks if @expire_at
149
151
  # remains the same, and do not release when the lock timestamp was overwritten.
@@ -169,6 +171,8 @@ class Redis::Lock
169
171
  end
170
172
 
171
173
  def try_extend
174
+ raise NotLocked.new('extend', self) unless @token
175
+
172
176
  @@extend_script ||= Script.new <<-LUA
173
177
  local key = KEYS[1]
174
178
  local key_group = KEYS[2]
@@ -242,4 +246,15 @@ class Redis::Lock
242
246
  "The following lock timed-out waiting to get aquired: #{@lock}"
243
247
  end
244
248
  end
249
+
250
+ class NotLocked < Error
251
+ def initialize(operation, lock)
252
+ @operation = operation
253
+ @lock = lock
254
+ end
255
+
256
+ def message
257
+ "Trying to #{@operation} a lock has not been aquired: #{@lock}"
258
+ end
259
+ end
245
260
  end
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class Lock
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust-redis-lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kareem Kouddous