gcra 1.1.0 → 1.2.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
- SHA1:
3
- metadata.gz: 9b29ec6abd01bba124433e5e331f1935e9ed5edc
4
- data.tar.gz: e44c984d0d02dd54f92959e9782d4b5d755f71b4
2
+ SHA256:
3
+ metadata.gz: b02bda1b59d67535c5f7e098f0553e7d79dab0baed8266668e4533eaf083fdd8
4
+ data.tar.gz: 12f92e851d067cc367180e9c4528f7564ffc487ddd62273fecd6450fbb8de894
5
5
  SHA512:
6
- metadata.gz: 3090609da18cda2a4807eff2e2fb7faf9a354dc996c159af0e42e1412448792196ba57151204cb96085e9a05417332e387c68cddb9a68fd0527a6123d99dd5de
7
- data.tar.gz: f18cd4c996c23bef845942364f387101d4ed452e24fe289e39ff9d5333a3059d6cedb6218eeba7050ca1ddc41f7a0db3af46d8adc0cce8bd498be8d0b984d5bd
6
+ metadata.gz: 993dfc9876b0b5f92e7456a20f1e9da2875505f41457540d7e8a41ea59f2e0080880ad96bc6e7b1751dbea67c60b4b416a88099350a5435c60b467f90f42e1fa
7
+ data.tar.gz: cdc1e40167c88d8a3749a8176c2683520973e844063ed3035e4b9be8533c1c07af7d8119ed8eec6a24e3c918850f914a55394784e3db06d8d9c0e91e5bb3eed0
@@ -16,11 +16,15 @@ module GCRA
16
16
  # Digest::SHA1.hexdigest(CAS_SCRIPT)
17
17
  CAS_SHA = "89118e702230c0d65969c5fc557a6e942a2f4d31".freeze
18
18
  CAS_SCRIPT_MISSING_KEY_RESPONSE = 'key does not exist'.freeze
19
- SCRIPT_NOT_IN_CACHE_RESPONSE = 'NOSCRIPT No matching script. Please use EVAL.'
19
+ SCRIPT_NOT_IN_CACHE_RESPONSE = 'NOSCRIPT No matching script. Please use EVAL.'.freeze
20
20
 
21
- def initialize(redis, key_prefix)
21
+ CONNECTED_TO_READONLY = "READONLY You can't write against a read only slave.".freeze
22
+
23
+ def initialize(redis, key_prefix, options = {})
22
24
  @redis = redis
23
25
  @key_prefix = key_prefix
26
+
27
+ @reconnect_on_readonly = options[:reconnect_on_readonly] || false
24
28
  end
25
29
 
26
30
  # Returns the value of the key or nil, if it isn't in the store.
@@ -43,8 +47,18 @@ module GCRA
43
47
  # Also set the key's expiration (ttl, in seconds).
44
48
  def set_if_not_exists_with_ttl(key, value, ttl_nano)
45
49
  full_key = @key_prefix + key
46
- ttl_milli = calculate_ttl_milli(ttl_nano)
47
- @redis.set(full_key, value, nx: true, px: ttl_milli)
50
+ retried = false
51
+ begin
52
+ ttl_milli = calculate_ttl_milli(ttl_nano)
53
+ @redis.set(full_key, value, nx: true, px: ttl_milli)
54
+ rescue Redis::CommandError => e
55
+ if e.message == CONNECTED_TO_READONLY && @reconnect_on_readonly && !retried
56
+ @redis.client.reconnect
57
+ retried = true
58
+ retry
59
+ end
60
+ raise
61
+ end
48
62
  end
49
63
 
50
64
  # Atomically compare the value at key to the old value. If it matches, set it to the new value
@@ -63,6 +77,10 @@ module GCRA
63
77
  @redis.script('load', CAS_SCRIPT)
64
78
  retried = true
65
79
  retry
80
+ elsif e.message == CONNECTED_TO_READONLY && @reconnect_on_readonly && !retried
81
+ @redis.client.reconnect
82
+ retried = true
83
+ retry
66
84
  end
67
85
  raise
68
86
  end
@@ -1,3 +1,3 @@
1
1
  module GCRA
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Frister
8
8
  - Tobias Schoknecht
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-02 00:00:00.000000000 Z
12
+ date: 2020-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -53,7 +53,7 @@ homepage: https://github.com/Barzahlen/gcra-ruby
53
53
  licenses:
54
54
  - MIT
55
55
  metadata: {}
56
- post_install_message:
56
+ post_install_message:
57
57
  rdoc_options: []
58
58
  require_paths:
59
59
  - lib
@@ -68,9 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 2.4.8
73
- signing_key:
71
+ rubygems_version: 3.0.6
72
+ signing_key:
74
73
  specification_version: 4
75
74
  summary: Ruby implementation of a generic cell rate algorithm (GCRA), ported from
76
75
  the Go implementation throttled.