Redis-backed rate limiter
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
LICENSE
README.md
Rakefile
redis_rate_limiter.gemspec

README.md

RedisRateLimiter

Build Status Coverage Status

Redis-backed rate limiter

Usage

Initialize with preferred limit for a given interval. For example, to rate limit an action 100 times a minute:

redis = Redis.new
rl = RedisRateLimiter.new("messages", redis, :limit => 100, :interval => 60)

Add to subject's count:

sender = "John"
rl.add(sender)

Check if subject has exceeded limit:

rl.exceeded?(sender)

Query number of seconds until subject is not rate limited (returns 0.0 if subject is not rate limited):

rl.retry_in?(sender)

Query number of events recorded for a given key

sender = "John"
3.times { rl.add(sender) }
rl.count(sender)
> 3
sleep 60
rl.count(sender)
> 0

Documentation

http://rubydoc.info/github/seanxiesx/redis_rate_limiter/master/frames