redis_rate_limit 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/redis_rate_limit/period.rb +16 -10
- data/lib/redis_rate_limit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99dd2f2459d45abe8d5f153986568e91507910f1
|
4
|
+
data.tar.gz: db64ac75e2dddc771d8420e0f2cc613868c0533a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55aeec8da24f5d09385c653271d6d9f78fb3a35e7fdc72be48c8693010b4fac8eb30782f324527890518ebf018d8d879e23fa5e9d7e235df4047c398db49cdae
|
7
|
+
data.tar.gz: 20b1d2fd90fac6ea078df01b9269844a00b3ce363861bcb5f5220c14ef50e4aacee1527aebe7aecd1e624bd47fea1dc8e437d1289ec9fe23005cc408b800ec6b
|
data/.gitignore
CHANGED
@@ -23,19 +23,25 @@ module RedisRateLimit
|
|
23
23
|
def get_access(client)
|
24
24
|
current_time = Time.now
|
25
25
|
range = current_time.strftime(@format)
|
26
|
-
current_counter = counter(client)
|
27
26
|
reset = current_time.to_i + @interval - (current_time.to_i % @interval)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
key_client = key(client)
|
28
|
+
counter = @redis.hincrby(key_client, range, 1)
|
29
|
+
|
30
|
+
if counter < @limit
|
31
|
+
pass = true
|
32
|
+
remaining = @limit - counter
|
33
|
+
else
|
34
|
+
pass = false
|
35
|
+
remaining = 0
|
33
36
|
end
|
34
|
-
|
35
|
-
remaining = @limit - counter
|
37
|
+
|
36
38
|
return {
|
37
|
-
"pass" =>
|
38
|
-
"RateLimit" => {
|
39
|
+
"pass" => pass,
|
40
|
+
"RateLimit" => {
|
41
|
+
"X-RateLimit-Limit" => @limit,
|
42
|
+
"X-RateLimit-Remaining" => remaining,
|
43
|
+
"X-RateLimit-Counter" => counter,
|
44
|
+
"X-RateLimit-Reset" => reset}
|
39
45
|
}
|
40
46
|
end
|
41
47
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_rate_limit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- neceha-bgl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|