rapidity 0.0.2.59005 → 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: 004e68dd80ed2ad9d0956207e413d092320406ef7d889956de8e93d9bf9b7327
4
- data.tar.gz: c2c05a95c87bb97655d0d0cf827a6db4294933315e2dc518c7fb398a4b82725d
3
+ metadata.gz: e5b2867053a9585cf900e8b33f71993636e8b685fea22a0735d03a45d7c36c44
4
+ data.tar.gz: 32d6e2e8dc7b06b5951044cf9d375ecf62e0e3c9093a184d6c71213066da387b
5
5
  SHA512:
6
- metadata.gz: e2eceaa1080720fdd72a47498dc7843f1387124d5519757eacf2217c6b85cf6384b7853cb904d33437de83bc2bad4d6a9b3db923331876687868157672913a6a
7
- data.tar.gz: 5d581e6817bb736228e333fcb6586c882a2ea9b8e98a0d3b3911b2dca08985d922fb1fc0e5f8f46e35a01a84cd9a2400def848482c5c2d8d5f21c1abeb922e3d
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.2.59005)
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,36 +29,49 @@ 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
42
42
  # @return count succesfuly obtained send slots
43
43
  def obtain(count = 5)
44
- _, taken = @pool.with do |conn|
44
+ count = count.abs
45
+
46
+ results = @pool.with do |conn|
45
47
  conn.multi do
46
48
  conn.set(key('remains'), threshold, ex: interval, nx: true)
47
49
  conn.decrby(key('remains'), count)
48
50
  end
49
51
  end
50
52
 
53
+ taken = results[1].to_i #=> conn.decrby(key('remains'), count)
54
+
51
55
  if taken < 0
52
56
  overflow = taken.abs
53
57
  to_return = [count, overflow].min
54
58
 
55
- @pool.with do |conn|
59
+ results = @pool.with do |conn|
56
60
  conn.multi do
57
61
  conn.set(key('remains'), threshold - to_return, ex: interval, nx: true)
58
62
  conn.incrby(key('remains'), to_return)
63
+ conn.ttl(key('remains'))
59
64
  end
60
65
  end
61
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
+
62
75
  count - to_return
63
76
  else
64
77
  count
@@ -1,6 +1,6 @@
1
1
  module Rapidity
2
2
 
3
- VERSION = '0.0.2'.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.2.59005
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: []