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 +4 -4
- data/lib/redis/lockers/lock.rb +3 -3
- data/lib/redis/lockers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 299a3b84d80ef9b5972510179cbeb68e08cc0e50971246ec4496bf1beefffbcb
|
4
|
+
data.tar.gz: ee55a1b3e4df0ce99b7e9921acdc467129166a63055c4a259345050f0af43322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47e8a04a6a9c10020c6469969448404ed42103975ec1195216fdec100623588ee8b1c5b2901ae52635a91d32027825d1cd61a56045e5225d804c35a994b5effa
|
7
|
+
data.tar.gz: cf8cfc08fbe28a993d2efca1314f5aa7aa55b2322f62919e4e111dc64a8e01f3d691c5ab93bed4edc259b457d88f6fed3831207de0538f92a13ab681984f94eb
|
data/lib/redis/lockers/lock.rb
CHANGED
@@ -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
|
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
|
39
|
+
success && timestamp <= deadline || false
|
40
40
|
end
|
41
41
|
|
42
42
|
# Release acquired lease.
|