gcra 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gcra/redis_store.rb +16 -8
- data/lib/gcra/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e37214a0a8181beff8863287ffdabee12b6cd6a4
|
4
|
+
data.tar.gz: d23082af239177bafeda35a8f4db1d0223d0d09a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75d41403c38028215e7afd7962ade25cb24c751e99ae349ee02c4a17d2f8ad26fb5510d81d108a70b32900aafec0161c588cf6b492c00a0995c099b34bc85c08
|
7
|
+
data.tar.gz: 945835400bcf67bbaa8e153c12fb612a08a626e59cd9cbc6b5d33045dfe43a627d80106113db847bc2855f00ab5de2ee2932421a48d489aef90d26c014bab53e
|
data/lib/gcra/redis_store.rb
CHANGED
@@ -9,11 +9,7 @@ module GCRA
|
|
9
9
|
if v ~= ARGV[1] then
|
10
10
|
return 0
|
11
11
|
end
|
12
|
-
|
13
|
-
redis.call('psetex', KEYS[1], ARGV[3], ARGV[2])
|
14
|
-
else
|
15
|
-
redis.call('set', KEYS[1], ARGV[2])
|
16
|
-
end
|
12
|
+
redis.call('psetex', KEYS[1], ARGV[3], ARGV[2])
|
17
13
|
return 1
|
18
14
|
EOF
|
19
15
|
CAS_SCRIPT_MISSING_KEY_RESPONSE = 'key does not exist'.freeze
|
@@ -43,8 +39,8 @@ module GCRA
|
|
43
39
|
full_key = @key_prefix + key
|
44
40
|
did_set = @redis.setnx(full_key, value)
|
45
41
|
|
46
|
-
if did_set
|
47
|
-
ttl_milli = ttl_nano
|
42
|
+
if did_set
|
43
|
+
ttl_milli = calculate_ttl_milli(ttl_nano)
|
48
44
|
@redis.pexpire(full_key, ttl_milli)
|
49
45
|
end
|
50
46
|
|
@@ -57,7 +53,7 @@ module GCRA
|
|
57
53
|
def compare_and_set_with_ttl(key, old_value, new_value, ttl_nano)
|
58
54
|
full_key = @key_prefix + key
|
59
55
|
begin
|
60
|
-
ttl_milli = ttl_nano
|
56
|
+
ttl_milli = calculate_ttl_milli(ttl_nano)
|
61
57
|
swapped = @redis.eval(CAS_SCRIPT, keys: [full_key], argv: [old_value, new_value, ttl_milli])
|
62
58
|
rescue Redis::CommandError => e
|
63
59
|
if e.message == CAS_SCRIPT_MISSING_KEY_RESPONSE
|
@@ -68,5 +64,17 @@ module GCRA
|
|
68
64
|
|
69
65
|
return swapped == 1
|
70
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def calculate_ttl_milli(ttl_nano)
|
71
|
+
ttl_milli = ttl_nano / 1_000_000
|
72
|
+
# Setting 0 as expiration/ttl would result in an error.
|
73
|
+
# Therefore overwrite it and use 1
|
74
|
+
if ttl_milli == 0
|
75
|
+
return 1
|
76
|
+
end
|
77
|
+
return ttl_milli
|
78
|
+
end
|
71
79
|
end
|
72
80
|
end
|
data/lib/gcra/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Frister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|