robust-redis-lock 0.2.1 → 0.2.2

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: 54f86e888f983a8c1edf31ef33f8c1f6aba3115c
4
- data.tar.gz: 3b1e4ba2965762f635971c099003dff10eceff72
3
+ metadata.gz: d7d9c9882c711325cf6560eaef7a0ea124a70575
4
+ data.tar.gz: d7f4c26f869c92382b7e2e0924749404e13c4c9a
5
5
  SHA512:
6
- metadata.gz: 37581c50322701227f16509c189854bda392cd3da9b03df6d33b44c0b9384d4c1c824038b4ad0b5717abcd53167257083948f3aeea71b6c2e82873dbc01167e9
7
- data.tar.gz: 139b0e46435e89baabc487fe6747dc1d24dd415fad58e58d28276ee4391667d10d05f03b594a5c83b716ba2ff62925bfcf940ccfd4be930491a6f273256fe2d2
6
+ metadata.gz: 3f6cb3c1b59df99f4c1531db778957d4279a186ce0c2d13c8515f70066528d7fdcb06060d08f63da3cce8dd1bb7093200f92dc9c69b0ac70367a3ebedf2a0d71
7
+ data.tar.gz: 22d94c6e9901cf5f6190306b2839e489d6015a1a33423d0030bca914ecbe567d78ec084d4f95acf6b94953a9e21ad950553e22fd648f9ae390e3534494eefc36
@@ -32,8 +32,8 @@ class Redis::Lock
32
32
 
33
33
  def lock
34
34
  result = false
35
- start_at = Time.now
36
- while Time.now - start_at < @timeout
35
+ start_at = now
36
+ while now - start_at < @timeout
37
37
  break if result = try_lock
38
38
  sleep @sleep.to_f
39
39
  end
@@ -46,8 +46,6 @@ class Redis::Lock
46
46
  end
47
47
 
48
48
  def try_lock
49
- now = Time.now.to_i
50
-
51
49
  # This script loading is not thread safe (touching a class variable), but
52
50
  # that's okay, because the race is harmless.
53
51
  @@lock_script ||= Script.new <<-LUA
@@ -72,7 +70,7 @@ class Redis::Lock
72
70
  return {'acquired', next_token}
73
71
  end
74
72
  LUA
75
- result, token = @@lock_script.eval(@redis, :keys => [@key], :argv => [now, now + @expire])
73
+ result, token = @@lock_script.eval(@redis, :keys => [@key], :argv => [now.to_i, now.to_i + @expire])
76
74
 
77
75
  @token = token if token
78
76
 
@@ -103,7 +101,6 @@ class Redis::Lock
103
101
  end
104
102
 
105
103
  def extend
106
- now = Time.now.to_i
107
104
  @@extend_script ||= Script.new <<-LUA
108
105
  local key = KEYS[1]
109
106
  local expires_at = tonumber(ARGV[1])
@@ -116,6 +113,10 @@ class Redis::Lock
116
113
  return false
117
114
  end
118
115
  LUA
119
- !!@@extend_script.eval(@redis, :keys => [@key], :argv => [now + @expire, @token])
116
+ !!@@extend_script.eval(@redis, :keys => [@key], :argv => [now.to_i + @expire, @token])
117
+ end
118
+
119
+ def now
120
+ Time.now
120
121
  end
121
122
  end
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class Lock
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
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: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kareem Kouddous