redis-throttler 0.1.7 → 0.1.8
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/ChangeLog.md +5 -0
- data/lib/redis-throttler/base.rb +1 -1
- data/lib/redis-throttler/configuration.rb +29 -0
- data/lib/redis-throttler/model.rb +2 -2
- data/lib/redis-throttler/version.rb +1 -1
- data/lib/redis-throttler.rb +9 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/throttler_spec.rb +14 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9048c65a94779c20e6b3c3218c819eed086199f
|
4
|
+
data.tar.gz: 0c651759bc3353b53bc35e556585c5a6b9f9bf21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9efc8ea572856bfadc8b81a076c8367ec83c624688488eb5b3c4ebaffcc390805370e1964efd10ea2e26de3c7c7b6087fb16880c97446e64a4317a8de0660641
|
7
|
+
data.tar.gz: cbfaa0d75eeb21064873e2ec7df7ec795c37e0dbd59abc1b677804dee57d17a981437aa6e775408e45c7930fa93af1dc5ade6b76a9f69b24ff056949238fc325
|
data/ChangeLog.md
CHANGED
data/lib/redis-throttler/base.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module RedisThrottler
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
def configuration
|
5
|
+
yield self
|
6
|
+
end
|
7
|
+
|
8
|
+
def define_setting(name, default = nil)
|
9
|
+
class_variable_set("@@#{name}", default)
|
10
|
+
|
11
|
+
define_class_method "#{name}=" do |value|
|
12
|
+
class_variable_set("@@#{name}", value)
|
13
|
+
end
|
14
|
+
|
15
|
+
define_class_method name do
|
16
|
+
class_variable_get("@@#{name}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def define_class_method(name, &block)
|
23
|
+
(class << self; self; end).instance_eval do
|
24
|
+
define_method name, &block
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -14,8 +14,8 @@ module RedisThrottler
|
|
14
14
|
key = "#{key.to_s}"
|
15
15
|
|
16
16
|
subject = opts[:by] || :id
|
17
|
-
limit = opts[:limit] ||
|
18
|
-
threshold = opts[:for] ||
|
17
|
+
limit = opts[:limit] || RedisThrottler.default_limit
|
18
|
+
threshold = opts[:for] || RedisThrottler.default_threshold
|
19
19
|
interval = opts[:interval] || ([threshold,120].max)/120
|
20
20
|
bucket_span = threshold * 2
|
21
21
|
|
data/lib/redis-throttler.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
require 'redis'
|
2
|
+
require 'redis-throttler/configuration'
|
2
3
|
require 'redis-throttler/model'
|
3
4
|
require 'redis-throttler/base'
|
4
5
|
|
6
|
+
|
5
7
|
module RedisThrottler
|
8
|
+
extend RedisThrottler::Configuration
|
9
|
+
|
10
|
+
define_setting :default_limit, 5
|
11
|
+
define_setting :default_threshold, 600
|
12
|
+
|
13
|
+
define_setting :redis, Redis.new(host: 'localhost', port: 6379)
|
14
|
+
|
6
15
|
def self.included(base)
|
7
16
|
base.include(RedisThrottler::Model)
|
8
17
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/throttler_spec.rb
CHANGED
@@ -7,6 +7,20 @@ describe RedisThrottler::Base do
|
|
7
7
|
@rl.send(:redis).flushdb
|
8
8
|
end
|
9
9
|
|
10
|
+
it 'configures properly' do
|
11
|
+
expect(RedisThrottler.default_limit).to eq(5)
|
12
|
+
expect(RedisThrottler.default_threshold).to eq(600)
|
13
|
+
expect(RedisThrottler.redis).to be_a(Redis)
|
14
|
+
|
15
|
+
RedisThrottler.configuration do |config|
|
16
|
+
config.default_limit = 10
|
17
|
+
config.default_threshold = 900
|
18
|
+
end
|
19
|
+
|
20
|
+
expect(RedisThrottler.default_limit).to eq(10)
|
21
|
+
expect(RedisThrottler.default_threshold).to eq(900)
|
22
|
+
end
|
23
|
+
|
10
24
|
it 'sets set_bucket_expiry to the bucket_span if not defined' do
|
11
25
|
expect(@rl.instance_variable_get(:@bucket_span)).to eq(@rl.instance_variable_get(:@bucket_expiry))
|
12
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-throttler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Surdam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- gemspec.yml
|
130
130
|
- lib/redis-throttler.rb
|
131
131
|
- lib/redis-throttler/base.rb
|
132
|
+
- lib/redis-throttler/configuration.rb
|
132
133
|
- lib/redis-throttler/model.rb
|
133
134
|
- lib/redis-throttler/version.rb
|
134
135
|
- redis-throttler.gemspec
|