rapidity 0.0.4 → 0.0.5.88265

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: e5b2867053a9585cf900e8b33f71993636e8b685fea22a0735d03a45d7c36c44
4
- data.tar.gz: 32d6e2e8dc7b06b5951044cf9d375ecf62e0e3c9093a184d6c71213066da387b
3
+ metadata.gz: 6faa9172962dc6c7004e59dc8e827f16572b99c41b586c7221539d2bf253dda5
4
+ data.tar.gz: fb698e043084b6ad4491c2c85b785f9678aba9996f333e3df6bae45d6f76a76a
5
5
  SHA512:
6
- metadata.gz: 47d2226e37cddfa6d743f550ca4522909874e5f0476be4447bc5aac7afe16aa43ca70f64c8196d805e23db104af705088e79af4ec7a1d0192830297950678b56
7
- data.tar.gz: 7fa7c1e532876677d1f4aef57cc36cb310b61382c5ca630cdc4b90e115eeb01e6020e419e66d322d89e424647c602294ed776c399b5eaff124a8fcc3fd8e5bcb
6
+ metadata.gz: d76e69e666ae0ab3a541f8ce725b2aae485ac9c7218163bd23bcaf4023f33db748da42f5dab7b978699f3f0ac3c0cfce9b49e2933127b81613d7df4533bc7496
7
+ data.tar.gz: 7434ad4f51dc20142d28f5df0bd004f79e8674dec8ac317683d18921626469525f81956ce4c3b7a8260c11cdb3cd7f281bb3f7f7aac5123e532899a9446d1587
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rapidity (0.0.4)
4
+ rapidity (0.0.5.88265)
5
5
  activesupport
6
6
  connection_pool
7
7
  redis
@@ -58,7 +58,7 @@ GEM
58
58
  psych (3.3.2)
59
59
  public_suffix (4.0.6)
60
60
  rainbow (3.0.0)
61
- redis (4.4.0)
61
+ redis (4.7.0)
62
62
  reek (6.0.4)
63
63
  kwalify (~> 0.7.0)
64
64
  parser (~> 3.0.0)
data/README.md CHANGED
@@ -0,0 +1,92 @@
1
+ # Rapidity
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rapidity.svg)](https://rubygems.org/gems/rapidity)
4
+ [![Gem](https://img.shields.io/gem/dt/rapidity.svg)](https://rubygems.org/gems/rapidity/versions)
5
+ [![YARD](https://badgen.net/badge/YARD/doc/blue)](http://www.rubydoc.info/gems/rapidity)
6
+
7
+ [![Coverage](https://lysander.rnds.pro/api/v1/badges/rapidity_coverage.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_coverage.html)
8
+ [![Quality](https://lysander.rnds.pro/api/v1/badges/rapidity_quality.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_quality.html)
9
+ [![Outdated](https://lysander.rnds.pro/api/v1/badges/rapidity_outdated.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_outdated.html)
10
+ [![Vulnerabilities](https://lysander.rnds.pro/api/v1/badges/rapidity_vulnerable.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_vulnerable.html)
11
+
12
+ Simple but fast Redis-backed distributed rate limiter. Allows you to specify time interval and count within to limit distributed operations.
13
+
14
+ Features:
15
+
16
+ - extremly simple
17
+ - safe
18
+ - fast
19
+
20
+ ## Usage
21
+
22
+ Rapidity has two variants:
23
+
24
+ - simple `Rapidity::Limiter` to handle single distibuted counter
25
+ - complex `Rapidity::Composer` to handle multiple counters at once
26
+
27
+ ### Single conter with concurrent access
28
+
29
+ ```ruby
30
+ pool = ConnectionPool.new(size: 10) do
31
+ Redis.new(url: ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379'))
32
+ end
33
+
34
+ # allow no more 10 requests within 5 seconds
35
+ limiter = Rapidity::Limiter.new(pool, name: 'requests', threshold: 10, interval: 5)
36
+
37
+ loop do
38
+ # try to obtain 3 requests at once
39
+ quota = limiter.obtain(3).times do
40
+ make_request
41
+ end
42
+
43
+ if quota == 0
44
+ # no more requests allowed within interval
45
+ sleep 1
46
+ end
47
+ end
48
+
49
+ ```
50
+
51
+ ### Multiple counters
52
+
53
+ ```ruby
54
+ pool = ConnectionPool.new(size: 10) do
55
+ Redis.new(url: ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379'))
56
+ end
57
+
58
+ LIMITS = [
59
+ { interval: 1, threshold: 2 }, # no more 2 requests per second
60
+ { interval: 60, threshold: 200 }, # no more 200 requests per minute
61
+ { interval: 86400, threshold: 10000 } # no more 10k requests per day
62
+ ]
63
+
64
+ limiter = Rapidity::Composer.new(pool, name: 'requests', limits: LIMITS)
65
+
66
+ loop do
67
+ # try to obtain 3 requests at once
68
+ quota = limiter.obtain(3).times do
69
+ make_request
70
+ end
71
+
72
+ if quota == 0
73
+ # no more requests allowed within interval
74
+ puts limiter.remains # inspect current limits
75
+ sleep 1
76
+ end
77
+ end
78
+
79
+ ```
80
+
81
+ ## Installation
82
+
83
+ It's a gem:
84
+ ```bash
85
+ gem install rapidity
86
+ ```
87
+ There's also the wonders of [the Gemfile](http://bundler.io):
88
+ ```ruby
89
+ gem 'rapidity'
90
+ ```
91
+
92
+
@@ -1,6 +1,6 @@
1
1
  module Rapidity
2
2
 
3
- VERSION = '0.0.4'.freeze
3
+ VERSION = '0.0.5'.freeze
4
4
 
5
5
  end
6
6
 
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapidity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5.88265
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
12
  date: 2022-06-25 00:00:00.000000000 Z
@@ -237,10 +237,10 @@ files:
237
237
  - lib/rapidity/composer.rb
238
238
  - lib/rapidity/limiter.rb
239
239
  - lib/rapidity/version.rb
240
- homepage:
240
+ homepage:
241
241
  licenses: []
242
242
  metadata: {}
243
- post_install_message:
243
+ post_install_message:
244
244
  rdoc_options: []
245
245
  require_paths:
246
246
  - lib
@@ -255,8 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  - !ruby/object:Gem::Version
256
256
  version: '0'
257
257
  requirements: []
258
- rubygems_version: 3.3.8
259
- signing_key:
258
+ rubygems_version: 3.0.3
259
+ signing_key:
260
260
  specification_version: 4
261
261
  summary: Simple distributed Redis-backed rate limiter
262
262
  test_files: []