gcra 1.2.0 → 1.3.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: b02bda1b59d67535c5f7e098f0553e7d79dab0baed8266668e4533eaf083fdd8
4
- data.tar.gz: 12f92e851d067cc367180e9c4528f7564ffc487ddd62273fecd6450fbb8de894
3
+ metadata.gz: d08cd7202437ad330ea13e7e5566e4d8625a951da36b5c096c53b0502f3d5d70
4
+ data.tar.gz: 9a7f6298e891d16172b6f08fce6adbf2e7f114a1309ab993e949ca485333bb38
5
5
  SHA512:
6
- metadata.gz: 993dfc9876b0b5f92e7456a20f1e9da2875505f41457540d7e8a41ea59f2e0080880ad96bc6e7b1751dbea67c60b4b416a88099350a5435c60b467f90f42e1fa
7
- data.tar.gz: cdc1e40167c88d8a3749a8176c2683520973e844063ed3035e4b9be8533c1c07af7d8119ed8eec6a24e3c918850f914a55394784e3db06d8d9c0e91e5bb3eed0
6
+ metadata.gz: cceec9abdfcc126ed38eec59778cf0ee4f1992d1414c61f545baee34cf9c590860ad6cfc3e6120a51369b1546f64c2dd30d47a43b95f40f66b0999ac150a3d27
7
+ data.tar.gz: e288210de6c6ac86d431468c881b438533490353b10040babd850da091e8aedb6788258adb7105a7b94240da93dfc4704cdb29dbb6ff3d3a253e2eba5e87921e
@@ -15,10 +15,10 @@ module GCRA
15
15
 
16
16
  # Digest::SHA1.hexdigest(CAS_SCRIPT)
17
17
  CAS_SHA = "89118e702230c0d65969c5fc557a6e942a2f4d31".freeze
18
- CAS_SCRIPT_MISSING_KEY_RESPONSE = 'key does not exist'.freeze
19
- SCRIPT_NOT_IN_CACHE_RESPONSE = 'NOSCRIPT No matching script. Please use EVAL.'.freeze
20
-
21
- CONNECTED_TO_READONLY = "READONLY You can't write against a read only slave.".freeze
18
+ CAS_SCRIPT_MISSING_KEY_RESPONSE_PATTERN = Regexp.new('^key does not exist')
19
+ SCRIPT_NOT_IN_CACHE_RESPONSE_PATTERN = Regexp.new(
20
+ '^NOSCRIPT No matching script. Please use EVAL.',
21
+ )
22
22
 
23
23
  def initialize(redis, key_prefix, options = {})
24
24
  @redis = redis
@@ -30,9 +30,9 @@ module GCRA
30
30
  # Returns the value of the key or nil, if it isn't in the store.
31
31
  # Also returns the time from the Redis server, with microsecond precision.
32
32
  def get_with_time(key)
33
- time_response, value = @redis.pipelined do
34
- @redis.time # returns tuple (seconds since epoch, microseconds)
35
- @redis.get(@key_prefix + key)
33
+ time_response, value = @redis.pipelined do |pipeline|
34
+ pipeline.time # returns tuple (seconds since epoch, microseconds)
35
+ pipeline.get(@key_prefix + key)
36
36
  end
37
37
  # Convert tuple to nanoseconds
38
38
  time = (time_response[0] * 1_000_000 + time_response[1]) * 1_000
@@ -51,9 +51,9 @@ module GCRA
51
51
  begin
52
52
  ttl_milli = calculate_ttl_milli(ttl_nano)
53
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
54
+ rescue Redis::ReadOnlyError => e
55
+ if @reconnect_on_readonly && !retried
56
+ @redis.close
57
57
  retried = true
58
58
  retry
59
59
  end
@@ -70,17 +70,20 @@ module GCRA
70
70
  begin
71
71
  ttl_milli = calculate_ttl_milli(ttl_nano)
72
72
  swapped = @redis.evalsha(CAS_SHA, keys: [full_key], argv: [old_value, new_value, ttl_milli])
73
+ rescue Redis::ReadOnlyError => e
74
+ if @reconnect_on_readonly && !retried
75
+ @redis.close
76
+ retried = true
77
+ retry
78
+ end
79
+ raise
73
80
  rescue Redis::CommandError => e
74
- if e.message == CAS_SCRIPT_MISSING_KEY_RESPONSE
81
+ if e.message =~ CAS_SCRIPT_MISSING_KEY_RESPONSE_PATTERN
75
82
  return false
76
- elsif e.message == SCRIPT_NOT_IN_CACHE_RESPONSE && !retried
83
+ elsif e.message =~ SCRIPT_NOT_IN_CACHE_RESPONSE_PATTERN && !retried
77
84
  @redis.script('load', CAS_SCRIPT)
78
85
  retried = true
79
86
  retry
80
- elsif e.message == CONNECTED_TO_READONLY && @reconnect_on_readonly && !retried
81
- @redis.client.reconnect
82
- retried = true
83
- retry
84
87
  end
85
88
  raise
86
89
  end
data/lib/gcra/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GCRA
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Frister
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-18 00:00:00.000000000 Z
12
+ date: 2024-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -17,31 +17,31 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '3.5'
20
+ version: '3.12'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '3.5'
27
+ version: '3.12'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: redis
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '3.3'
34
+ version: '5.1'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '3.3'
41
+ version: '5.1'
42
42
  description: GCRA implementation for rate limiting
43
43
  email:
44
- - tobias.schoknecht@barzahlen.de
44
+ - tobias.schoknecht@viafintech.com
45
45
  executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
@@ -49,7 +49,7 @@ files:
49
49
  - lib/gcra/rate_limiter.rb
50
50
  - lib/gcra/redis_store.rb
51
51
  - lib/gcra/version.rb
52
- homepage: https://github.com/Barzahlen/gcra-ruby
52
+ homepage: https://github.com/viafintech/gcra-ruby
53
53
  licenses:
54
54
  - MIT
55
55
  metadata: {}
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.0.6
71
+ rubygems_version: 3.4.14
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Ruby implementation of a generic cell rate algorithm (GCRA), ported from