mario-redis-lock 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/redis_lock.rb +7 -3
- 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: 2853868a970109fa52abc01236f6107c2d4dbded
|
4
|
+
data.tar.gz: 6cdecec78e8585b1b24c142100d80900a75ea16e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48204bca5b65a3073ccbfe5edbf54a71424388381daf698c8ecc11689496063fe5039d41acbe222d4e1d6d87cb13bdab692db1911aa47a939da061518fedd3b6
|
7
|
+
data.tar.gz: ee01cdf3e836303897dd3c459ca0e6ec6b07979358c75115025c26c254fc1816d7472dda43873e33ef212c9589499d97f57788936430b6d8229ac741dc64db4b
|
data/README.md
CHANGED
@@ -17,15 +17,15 @@ Requirements:
|
|
17
17
|
* [Redis](http://redis.io/) >= 2.6.12
|
18
18
|
* [redis gem](https://rubygems.org/gems/redis) >= 3.0.5
|
19
19
|
|
20
|
-
The required versions are
|
20
|
+
The required versions are needed for the new syntax of the SET command, to easily implement the robust locking algorithm described in the [SET command documentation](http://redis.io/commands/set).
|
21
21
|
|
22
|
-
|
22
|
+
Install from RubyGems:
|
23
23
|
|
24
|
-
gem
|
24
|
+
$ gem install mario-redis-lock
|
25
25
|
|
26
|
-
|
26
|
+
Or include it in your project's `Gemfile` with Bundler:
|
27
27
|
|
28
|
-
|
28
|
+
gem 'mario-redis-lock', :require => 'redis_lock'
|
29
29
|
|
30
30
|
|
31
31
|
## Usage
|
data/lib/redis_lock.rb
CHANGED
@@ -4,7 +4,7 @@ require 'securerandom' # SecureRandom (from stdlib)
|
|
4
4
|
class RedisLock
|
5
5
|
|
6
6
|
# Gem version
|
7
|
-
VERSION = "1.0.
|
7
|
+
VERSION = "1.0.1"
|
8
8
|
|
9
9
|
# Original defaults
|
10
10
|
DEFAULT_ATTRS = {
|
@@ -104,8 +104,12 @@ class RedisLock
|
|
104
104
|
# * :not_acquired if the lock was not acquired (no release action was made because it was not needed)
|
105
105
|
def release
|
106
106
|
if acquired?
|
107
|
-
|
108
|
-
|
107
|
+
if redis.respond_to? :eval # if eval command is available, run a lua script because is a faster way to remove the key
|
108
|
+
script = 'if redis.call("get",KEYS[1]) == ARGV[1] then return redis.call("del",KEYS[1]) else return nil end'
|
109
|
+
ret = redis.eval(script, [key], [self.acquired_token])
|
110
|
+
else # i.e. MockRedis doesn't have eval
|
111
|
+
ret = if redis.get(key) == self.acquired_token then redis.del(key) else nil end
|
112
|
+
end
|
109
113
|
self.acquired_token = nil # cleanup acquired token
|
110
114
|
if ret == nil
|
111
115
|
:already_released
|