redis-lockers 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: a851912fde0e448b9ea869edc8e4d987085d97be49e16a9d9c423b0784ccb6ee
4
- data.tar.gz: ebdc57a08b43f6a958aefc9d4592c8a61c30a9610a5dba6cf51366f19ced3399
3
+ metadata.gz: 299a3b84d80ef9b5972510179cbeb68e08cc0e50971246ec4496bf1beefffbcb
4
+ data.tar.gz: ee55a1b3e4df0ce99b7e9921acdc467129166a63055c4a259345050f0af43322
5
5
  SHA512:
6
- metadata.gz: 573be720690cc6f04b3e75cfb19b1e4518f1c31aa423e54216e27d6c18ed1e25291c2f44d58761ba1240b6941c0bedbeb2cebe4b7010bc8b6a92932d6c55a3b1
7
- data.tar.gz: 6ebf339fffae54308e09e01f46b76234ea2bf5ca958ab45d6f8e0ba19d2c8d3991f33ac40154b5b786fb645bd7091a8208514dcb51128b9405de1b988866b3c2
6
+ metadata.gz: 47e8a04a6a9c10020c6469969448404ed42103975ec1195216fdec100623588ee8b1c5b2901ae52635a91d32027825d1cd61a56045e5225d804c35a994b5effa
7
+ data.tar.gz: cf8cfc08fbe28a993d2efca1314f5aa7aa55b2322f62919e4e111dc64a8e01f3d691c5ab93bed4edc259b457d88f6fed3831207de0538f92a13ab681984f94eb
@@ -21,7 +21,7 @@ class Redis
21
21
  def initialize(key, ttl:)
22
22
  @key = key.to_s
23
23
  @ttl = ttl.to_i
24
- @drift = @ttl * 0.01 + 2
24
+ @drift = @ttl * 0.01 + 2.0
25
25
  @nonce = SecureRandom.uuid
26
26
  end
27
27
 
@@ -30,13 +30,13 @@ class Redis
30
30
  # @param redis [Redis] Redis client
31
31
  # @return [Boolean] whenever lock was acquired or not.
32
32
  def acquire(redis)
33
- deadline = timestamp + @ttl + @drift
33
+ deadline = timestamp + @ttl - @drift
34
34
  success = LOCK_SCRIPT.eval(redis, {
35
35
  :keys => [@key],
36
36
  :argv => [@nonce, @ttl]
37
37
  })
38
38
 
39
- success && timestamp < deadline || false
39
+ success && timestamp <= deadline || false
40
40
  end
41
41
 
42
42
  # Release acquired lease.
@@ -3,6 +3,6 @@
3
3
  class Redis
4
4
  module Lockers
5
5
  # Gem version.
6
- VERSION = "1.0.0"
6
+ VERSION = "1.1.0"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-lockers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Zapparov