Sha256: 1cb19014479ffa691f298fa5665bf317056c4a3d04264eb33559267fb5f9efbc

Contents?: true

Size: 556 Bytes

Versions: 2

Compression:

Stored size: 556 Bytes

Contents

require 'redis'
require 'congestion/version'
require 'congestion/rate_limiter'

module Congestion
  class << self
    attr_accessor :default_options
    attr_accessor :redis
  end

  self.default_options = {
    namespace: 'congestion', # Redis key namespace
    interval: 1,             # 1 second
    max_in_interval: 1,      # 1 / second
    min_delay: 0,            # none
    track_rejected: true
  }

  self.redis = ->{
    Redis.new
  }

  def self.request(key, opts = { })
    RateLimiter.new redis.call, key, default_options.merge(opts)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
congestion-0.1.0 lib/congestion.rb
congestion-0.0.3 lib/congestion.rb