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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/lib/redis_lock.rb +7 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95b3e9086bb1024011a80e88878afff422e0fc5a
4
- data.tar.gz: 0c44db03346780a1c8ad274f59978ef4e0f985f4
3
+ metadata.gz: 2853868a970109fa52abc01236f6107c2d4dbded
4
+ data.tar.gz: 6cdecec78e8585b1b24c142100d80900a75ea16e
5
5
  SHA512:
6
- metadata.gz: 5e5b5faed6e289c517d75b30652b817f30ff89bc4560645b59129cdfab7ecdec3b14ec01f8fe46131d1f5b1c6ee02b18eaa853966a9bb534cd5df07824753915
7
- data.tar.gz: 2c4f6b91b32b0881074a76d0e6679c40bd18b098a9cdb7fd9b7b712d7a0697a9d5e8ad0aed44f8245ddb272607ec0e1ecfd5f8355e35109134139a86e9c00681
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 because I use the new syntax for the SET command to easily implement the robust algorithm described in the [SET command documentation](http://redis.io/commands/set).
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
- To install with bundler, add this line to your application's Gemfile:
22
+ Install from RubyGems:
23
23
 
24
- gem 'mario-redis-lock'
24
+ $ gem install mario-redis-lock
25
25
 
26
- Ot install it yourself as:
26
+ Or include it in your project's `Gemfile` with Bundler:
27
27
 
28
- $ gem install mario-redis-lock
28
+ gem 'mario-redis-lock', :require => 'redis_lock'
29
29
 
30
30
 
31
31
  ## Usage
@@ -4,7 +4,7 @@ require 'securerandom' # SecureRandom (from stdlib)
4
4
  class RedisLock
5
5
 
6
6
  # Gem version
7
- VERSION = "1.0.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
- script = 'if redis.call("get",KEYS[1]) == ARGV[1] then return redis.call("del",KEYS[1]) else return nil end'
108
- ret = redis.eval(script, [key], [self.acquired_token])
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mario-redis-lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Izquierdo