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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bb561742b30caf0fde6c6483febf005b1977d81
4
- data.tar.gz: 0616bfb579d95deaf434aa1f845d4a6de5e729c4
3
+ metadata.gz: 99dd2f2459d45abe8d5f153986568e91507910f1
4
+ data.tar.gz: db64ac75e2dddc771d8420e0f2cc613868c0533a
5
5
  SHA512:
6
- metadata.gz: e7706879fcdc0731ba444d8420a9b19d157cf87eda6b3521b558ea09b7314bb72d42fc051a19e90636ca47d94809067f00e5b98d6e4c649e829d8df1b2a02675
7
- data.tar.gz: f0865113f790f8f519e62c70749af4e7526b6c062e7b139f8a358d18bb6ac27e97f54c81fc1cd152d3150a9025c9413b6318952ee72dbca0e5ecca4c8fc7e1ce
6
+ metadata.gz: 55aeec8da24f5d09385c653271d6d9f78fb3a35e7fdc72be48c8693010b4fac8eb30782f324527890518ebf018d8d879e23fa5e9d7e235df4047c398db49cdae
7
+ data.tar.gz: 20b1d2fd90fac6ea078df01b9269844a00b3ce363861bcb5f5220c14ef50e4aacee1527aebe7aecd1e624bd47fea1dc8e437d1289ec9fe23005cc408b800ec6b
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /redis_rate_limit-*.gem
@@ -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
- unless current_counter < @limit
29
- return {
30
- "pass" => false,
31
- "RateLimit" => {"X-RateLimit-Limit" => @limit, "X-RateLimit-Remaining" => 0, "X-RateLimit-Reset" => reset}
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
- counter = @redis.hincrby(key(client), range, 1)
35
- remaining = @limit - counter
37
+
36
38
  return {
37
- "pass" => true,
38
- "RateLimit" => {"X-RateLimit-Limit" => @limit, "X-RateLimit-Remaining" => remaining, "X-RateLimit-Reset" => reset}
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
 
@@ -1,3 +1,3 @@
1
1
  module RedisRateLimit
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
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: 1.0.0
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-06 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis