module Throttle

Constants

ThrottledError
VERSION

Attributes

default_ns[RW]
default_polling[RW]
default_redis_client[RW]
default_timeout[RW]

Public Class Methods

for(key, max_per_second = nil, opts = {}, &block) click to toggle source
# 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