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 +4 -4
- data/README.md +1 -1
- data/lib/redis-gcra.rb +4 -0
- data/lib/redis-gcra/version.rb +1 -1
- data/vendor/inspect_gcra_ratelimit.lua +8 -3
- data/vendor/perform_gcra_ratelimit.lua +8 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9270bb6ad891cabb878ef0f7dc374f1bf3b872cd
|
4
|
+
data.tar.gz: 70830bbaf79eba417b109b971d6708f94cd52d18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f082ff34c4a09ab68e2262c2b8733250110a86142707bb1ad01b557e008adb1cecf0dcca05eebdc525d166282aaff76fa339f6a3a09d7cf21a391f01eb84dee
|
7
|
+
data.tar.gz: 78ab41650d4b1bf08808ba8a2b02d594451bdddc3ba81d54f7c9bdde574ae0cfd254c0beeb410a67e7b29118c1930dcb1fc56198260c828e6682891e0d4719a2
|
data/README.md
CHANGED
data/lib/redis-gcra.rb
CHANGED
@@ -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
|
data/lib/redis-gcra/version.rb
CHANGED
@@ -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
|
12
|
-
-- point number
|
13
|
-
|
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
|
17
|
-
-- point number
|
18
|
-
|
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.
|
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-
|
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.
|
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
|