redis_rate_limiter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/redis_rate_limiter.rb +4 -4
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 131cc6a6a6693dd690435dc804387a1f3bd82f28e7d3ff75b0ebe8d3ca23645f
|
4
|
+
data.tar.gz: d996d586a2676b65dc68eaefde091f217d697715629f13ef8a5abcf486490978
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8744a7a0947b3a242d7a220fcb0f6b06cb0202699b8bea34727f9e8ab65f00abbe7b7caf3c6b46454c773e22d2d3586cbc553dd1bf1f365d86fc16b4e0d25ec
|
7
|
+
data.tar.gz: 0a8d6010cd67df6215d89e0d98f6b6f8264b1baba4c171528ceadeba955dfe9e043c05029e201585b38f75a06c74951272485b0528f0e3ea18b87888c8aad1e7
|
data/lib/redis_rate_limiter.rb
CHANGED
@@ -32,10 +32,10 @@ class RedisRateLimiter
|
|
32
32
|
# @param [time] time UNIX timestamp of event
|
33
33
|
def add subject, time = Time.now.to_f
|
34
34
|
subject_key = "#{@key}:#{subject}"
|
35
|
-
@redis.multi do
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
@redis.multi do |pipeline|
|
36
|
+
pipeline.lpush(subject_key, time)
|
37
|
+
pipeline.ltrim(subject_key, 0, @limit - 1)
|
38
|
+
pipeline.expire(subject_key, @interval)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_rate_limiter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Xie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
|
-
|
152
|
-
rubygems_version: 2.3.0
|
151
|
+
rubygems_version: 3.0.3.1
|
153
152
|
signing_key:
|
154
153
|
specification_version: 4
|
155
154
|
summary: Redis-backed rate limiter
|