Skip to content
Daniel Pepper edited this page Sep 14, 2022 · 6 revisions

All systems have limits, beyond which they tend to fail. Berater makes working within these limits easy.

require 'berater'
require 'redis'

Berater.configure do |c|
  c.redis = Redis.new
end

Berater(:key, 3) do
  # allow only three simultaneous requests at a time, with a concurrency limiter
end

Berater(:key, 2, interval: 60) do
  # or do work twice per minute with a rate limiter
end

Usage

Berater(key, capacity, **opts, &block)
  • key - name of limiter
  • capacity - maximum number of requests permitted
  • opts
    • interval - how often the capacity limit resets, if it does (either number of seconds or a symbol: :second, :minute, hour)
    • redis - a redis instance
  • block - optional block to execute if within limits
Clone this wiki locally