Module: Throttle
- Defined in:
- lib/throttle.rb,
lib/throttle/version.rb,
lib/throttle/instance.rb,
lib/throttle/redis_script.rb
Defined Under Namespace
Classes: Instance, RedisScript
Constant Summary collapse
- ThrottledError =
Class.new(StandardError)
- VERSION =
"0.0.3"
Class Attribute Summary collapse
-
.default_ns ⇒ Object
Returns the value of attribute default_ns.
-
.default_polling ⇒ Object
Returns the value of attribute default_polling.
-
.default_redis_client ⇒ Object
Returns the value of attribute default_redis_client.
-
.default_timeout ⇒ Object
Returns the value of attribute default_timeout.
Class Method Summary collapse
Class Attribute Details
.default_ns ⇒ Object
Returns the value of attribute default_ns.
10 11 12 |
# File 'lib/throttle.rb', line 10 def default_ns @default_ns end |
.default_polling ⇒ Object
Returns the value of attribute default_polling.
10 11 12 |
# File 'lib/throttle.rb', line 10 def default_polling @default_polling end |
.default_redis_client ⇒ Object
Returns the value of attribute default_redis_client.
10 11 12 |
# File 'lib/throttle.rb', line 10 def default_redis_client @default_redis_client end |
.default_timeout ⇒ Object
Returns the value of attribute default_timeout.
10 11 12 |
# File 'lib/throttle.rb', line 10 def default_timeout @default_timeout end |
Class Method Details
.for(key, max_per_second = nil, opts = {}, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/throttle.rb', line 15 def for(key, max_per_second = nil, opts = {}, &block) polling = opts[:polling] || Throttle.default_polling timeout = opts[:timeout] || Throttle.default_timeout redis = opts[:redis] || Throttle.default_redis_client namespace = opts[:ns] || Throttle.default_ns strategy = RedisScript.new(redis, "#{namespace}:#{key}", max_per_second) strategy.set_bucket_size! instance = Instance.new(strategy, polling, timeout) block_given? ? instance.limit(&block) : instance end |