rapidity 0.0.3.59007 → 0.0.4

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: 40693850bff25145da969b8f51894fbb7b01dc774ab6534e38cad3c4c461cbc7
4
- data.tar.gz: be8657014c79b06a6e7191d3e2aff293720ac5e9418591d3a4e962de4e4774eb
3
+ metadata.gz: e5b2867053a9585cf900e8b33f71993636e8b685fea22a0735d03a45d7c36c44
4
+ data.tar.gz: 32d6e2e8dc7b06b5951044cf9d375ecf62e0e3c9093a184d6c71213066da387b
5
5
  SHA512:
6
- metadata.gz: f18ecca6be2877265cfa7d2afa434d515668502ea820a7fa0a41c805ab59e6163acda6c52b46dddc2c8396265e05ea8947c6b2f48e4c8c4dec3544ee23ac33e0
7
- data.tar.gz: 28869c4c007d2dba9012c006c5b09ab7157d0ce592a4ad891f365c5036096c28a9b9ddb1d85d17ecf31c744be07f09cdf924a6a4d73e594f200e416e8ce24e8c
6
+ metadata.gz: 47d2226e37cddfa6d743f550ca4522909874e5f0476be4447bc5aac7afe16aa43ca70f64c8196d805e23db104af705088e79af4ec7a1d0192830297950678b56
7
+ data.tar.gz: 7fa7c1e532876677d1f4aef57cc36cb310b61382c5ca630cdc4b90e115eeb01e6020e419e66d322d89e424647c602294ed776c399b5eaff124a8fcc3fd8e5bcb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rapidity (0.0.3.59007)
4
+ rapidity (0.0.4)
5
5
  activesupport
6
6
  connection_pool
7
7
  redis
@@ -142,4 +142,4 @@ DEPENDENCIES
142
142
  timeouter
143
143
 
144
144
  BUNDLED WITH
145
- 2.2.14
145
+ 2.2.27
data/README.md ADDED
File without changes
@@ -29,13 +29,13 @@ module Rapidity
29
29
  # Get current counter
30
30
  # @return remaining counter value
31
31
  def remains
32
- _, result = @pool.with do |conn|
32
+ results = @pool.with do |conn|
33
33
  conn.multi do
34
34
  conn.set(key('remains'), threshold, ex: interval, nx: true)
35
35
  conn.get(key('remains'))
36
36
  end
37
37
  end
38
- result.to_i
38
+ results[1].to_i #=> conn.get(key('remains'))
39
39
  end
40
40
 
41
41
  # Obtain values from counter
@@ -43,24 +43,35 @@ module Rapidity
43
43
  def obtain(count = 5)
44
44
  count = count.abs
45
45
 
46
- _, taken = @pool.with do |conn|
46
+ results = @pool.with do |conn|
47
47
  conn.multi do
48
48
  conn.set(key('remains'), threshold, ex: interval, nx: true)
49
49
  conn.decrby(key('remains'), count)
50
50
  end
51
51
  end
52
52
 
53
+ taken = results[1].to_i #=> conn.decrby(key('remains'), count)
54
+
53
55
  if taken < 0
54
56
  overflow = taken.abs
55
57
  to_return = [count, overflow].min
56
58
 
57
- @pool.with do |conn|
59
+ results = @pool.with do |conn|
58
60
  conn.multi do
59
61
  conn.set(key('remains'), threshold - to_return, ex: interval, nx: true)
60
62
  conn.incrby(key('remains'), to_return)
63
+ conn.ttl(key('remains'))
61
64
  end
62
65
  end
63
66
 
67
+ ttl = results[2].to_i #=> conn.ttl(key('remains'))
68
+
69
+ # reset if no ttl present
70
+ if ttl == -1
71
+ STDERR.puts "ERROR[#{Time.now}]: TTL for key #{key('remains').inspect} disappeared!"
72
+ @pool.with {|c| c.expire(key('remains'), interval) }
73
+ end
74
+
64
75
  count - to_return
65
76
  else
66
77
  count
@@ -1,6 +1,6 @@
1
1
  module Rapidity
2
2
 
3
- VERSION = '0.0.3'.freeze
3
+ VERSION = '0.0.4'.freeze
4
4
 
5
5
  end
6
6
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapidity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.59007
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yurusov Vlad
8
8
  - Samoilenko Yuri
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-04 00:00:00.000000000 Z
12
+ date: 2022-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -232,14 +232,15 @@ files:
232
232
  - Gemfile
233
233
  - Gemfile.lock
234
234
  - LICENSE
235
+ - README.md
235
236
  - lib/rapidity.rb
236
237
  - lib/rapidity/composer.rb
237
238
  - lib/rapidity/limiter.rb
238
239
  - lib/rapidity/version.rb
239
- homepage:
240
+ homepage:
240
241
  licenses: []
241
242
  metadata: {}
242
- post_install_message:
243
+ post_install_message:
243
244
  rdoc_options: []
244
245
  require_paths:
245
246
  - lib
@@ -254,8 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
255
  - !ruby/object:Gem::Version
255
256
  version: '0'
256
257
  requirements: []
257
- rubygems_version: 3.0.3
258
- signing_key:
258
+ rubygems_version: 3.3.8
259
+ signing_key:
259
260
  specification_version: 4
260
261
  summary: Simple distributed Redis-backed rate limiter
261
262
  test_files: []