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 +4 -4
- data/lib/redis-lock.rb +15 -0
- 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: 8da8da8a1f759bf85402feeb3985aee0fdf917c6
|
4
|
+
data.tar.gz: 3c69f1a649c2d26b069db228980e0427bf8574dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2235d3e0b9658712cd1a8ca17fc697f0ed7257fd3a70d5710183984a6850d213fb67b8e988946788f495a3c2cdf77b034e2757ec5f993dbdc1355d26eda3ea16
|
7
|
+
data.tar.gz: f9c0d7ee0acd79c40d10185a78fdcad8fa1531090202c79b2f6070a9a6333259802cc41d664fa3603a3bd7829741318a8d952eda5087c2b3b2097c3083fea5a1
|
data/lib/redis-lock.rb
CHANGED
@@ -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
|