Skip to content

januszry/redis-rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-rate-limiter

rate limiter implemented with redis lua script

NOTE: redis will lock whole server while executing a script, so better use a standalone redis for rate-limiter

Features:

  • Check and set (CAS) is implemented with lua script. This is probably the only way to support CAS for single redis client. (See https://redis.io/commands/eval)
  • Support punishment. If a limiter is reached and punishment is set, same event will be banned for a specified period.

Flow:

  • For every limiter, no more than limit events can pass.
  • If only the event passed all limiters, the event can pass.
  • If the event passed all limiters and the counter equals limit and there is any punishment, ban this event with maximum of all punishments of limiters.

Limiter configuration example:

[
  { period: 60, limit: 3, punishment: 60 * 15 },
  { period: 60 * 60, limit: 9 },
]

see examples for more details

About

rate limiter with redis lua script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages