redis-gcra 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4ce10313659f0a4e111a77b037e45afff5e44f9
4
- data.tar.gz: 791b63e5937c82a7e0757064edb45016bb90e3df
3
+ metadata.gz: 9270bb6ad891cabb878ef0f7dc374f1bf3b872cd
4
+ data.tar.gz: 70830bbaf79eba417b109b971d6708f94cd52d18
5
5
  SHA512:
6
- metadata.gz: 4dd33796a611fe9c0d57eae0ba2ff2d7b95a38c8f3da96e98b42f9a9c57a923b53d412c103d43319e2a20c019692be07a8ad9f81366d1ba1e7a85b1fdafe9120
7
- data.tar.gz: 581125696884139ac3b83972aac95c859a9ee4c163e64b1b02a24e2b52705374dae48e5f76b08da84d240bf935fa60123147391ed3b048ca8d9ebd53e38970da
6
+ metadata.gz: 9f082ff34c4a09ab68e2262c2b8733250110a86142707bb1ad01b557e008adb1cecf0dcca05eebdc525d166282aaff76fa339f6a3a09d7cf21a391f01eb84dee
7
+ data.tar.gz: 78ab41650d4b1bf08808ba8a2b02d594451bdddc3ba81d54f7c9bdde574ae0cfd254c0beeb410a67e7b29118c1930dcb1fc56198260c828e6682891e0d4719a2
data/README.md CHANGED
@@ -69,7 +69,7 @@ without actually modifying the state. In order to do that, use the `peek`
69
69
  method:
70
70
 
71
71
  ```ruby
72
- RedisGCRA.peek(
72
+ result = RedisGCRA.peek(
73
73
  redis: redis,
74
74
  key: "overall-account/bob@example.com",
75
75
  burst: 1000,
@@ -1,3 +1,4 @@
1
+ require "digest/sha1"
1
2
  require "thread"
2
3
 
3
4
  module RedisGCRA
@@ -50,6 +51,9 @@ module RedisGCRA
50
51
 
51
52
  def load_script(redis, script_name)
52
53
  script_path = File.expand_path("../../vendor/#{script_name}.lua", __FILE__)
54
+ script = File.read(script_path)
55
+ script_sha = Digest::SHA1.hexdigest(script)
56
+ return script_sha if redis.script(:exists, script_sha)
53
57
  redis.script(:load, File.read(script_path))
54
58
  end
55
59
  end
@@ -1,3 +1,3 @@
1
1
  module RedisGCRA
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -8,9 +8,14 @@ local burst_offset = emission_interval * burst
8
8
  local now = redis.call("TIME")
9
9
 
10
10
  -- redis returns time as an array containing two integers: seconds of the epoch
11
- -- time and microseconds. for convenience we need to convert them to float
12
- -- point number
13
- now = now[1] + now[2] / 1000000
11
+ -- time (10 digits) and microseconds (6 digits). for convenience we need to
12
+ -- convert them to a floating point number. the resulting number is 16 digits,
13
+ -- bordering on the limits of a 64-bit double-precision floating point number.
14
+ -- adjust the epoch to be relative to Jan 1, 2017 00:00:00 GMT to avoid floating
15
+ -- point problems. this approach is good until "now" is 2,483,228,799 (Wed, 09
16
+ -- Sep 2048 01:46:39 GMT), when the adjusted value is 16 digits.
17
+ local jan_1_2017 = 1483228800
18
+ now = (now[1] - jan_1_2017) + (now[2] / 1000000)
14
19
 
15
20
  local tat = redis.call("GET", rate_limit_key)
16
21
 
@@ -13,9 +13,14 @@ local burst_offset = emission_interval * burst
13
13
  local now = redis.call("TIME")
14
14
 
15
15
  -- redis returns time as an array containing two integers: seconds of the epoch
16
- -- time and microseconds. for convenience we need to convert them to float
17
- -- point number
18
- now = now[1] + now[2] / 1000000
16
+ -- time (10 digits) and microseconds (6 digits). for convenience we need to
17
+ -- convert them to a floating point number. the resulting number is 16 digits,
18
+ -- bordering on the limits of a 64-bit double-precision floating point number.
19
+ -- adjust the epoch to be relative to Jan 1, 2017 00:00:00 GMT to avoid floating
20
+ -- point problems. this approach is good until "now" is 2,483,228,799 (Wed, 09
21
+ -- Sep 2048 01:46:39 GMT), when the adjusted value is 16 digits.
22
+ local jan_1_2017 = 1483228800
23
+ now = (now[1] - jan_1_2017) + (now[2] / 1000000)
19
24
 
20
25
  local tat = redis.call("GET", rate_limit_key)
21
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-gcra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pravosud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-26 00:00:00.000000000 Z
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.6.8
61
+ rubygems_version: 2.6.12
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Rate limiting based on Generic Cell Rate Algorithm