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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +0 -0
- data/lib/rapidity/limiter.rb +17 -4
- data/lib/rapidity/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5b2867053a9585cf900e8b33f71993636e8b685fea22a0735d03a45d7c36c44
|
4
|
+
data.tar.gz: 32d6e2e8dc7b06b5951044cf9d375ecf62e0e3c9093a184d6c71213066da387b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47d2226e37cddfa6d743f550ca4522909874e5f0476be4447bc5aac7afe16aa43ca70f64c8196d805e23db104af705088e79af4ec7a1d0192830297950678b56
|
7
|
+
data.tar.gz: 7fa7c1e532876677d1f4aef57cc36cb310b61382c5ca630cdc4b90e115eeb01e6020e419e66d322d89e424647c602294ed776c399b5eaff124a8fcc3fd8e5bcb
|
data/Gemfile.lock
CHANGED
data/README.md
ADDED
File without changes
|
data/lib/rapidity/limiter.rb
CHANGED
@@ -29,36 +29,49 @@ module Rapidity
|
|
29
29
|
# Get current counter
|
30
30
|
# @return remaining counter value
|
31
31
|
def remains
|
32
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/rapidity/version.rb
CHANGED
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.
|
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:
|
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.
|
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: []
|