Skip to content

seanxiesx/redis_rate_limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Redis-backed rate limiter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages