All Projects → ejfinneran → Ratelimit

ejfinneran / Ratelimit

Licence: mit
A Redis-backed rate limiter written in Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Ratelimit

Redis4cats
🔖 Redis client built on top of Cats Effect, Fs2 and Lettuce
Stars: ✭ 189 (-4.06%)
Mutual labels:  redis
Interviewguide
《大厂面试指北》——包括Java基础、JVM、数据库、mysql、redis、计算机网络、算法、数据结构、操作系统、设计模式、系统设计、框架原理。最佳阅读地址:http://notfound9.github.io/interviewGuide/
Stars: ✭ 3,117 (+1482.23%)
Mutual labels:  redis
Dsock
Distributed WebSocket broker
Stars: ✭ 197 (+0%)
Mutual labels:  redis
Zi5book
book.zi5.me全站kindle电子书籍爬取,按照作者书籍名分类,每本书有mobi和equb两种格式,采用分布式进行全站爬取
Stars: ✭ 191 (-3.05%)
Mutual labels:  redis
Rate Limit
🚔 General purpose rate limiter implementation.
Stars: ✭ 193 (-2.03%)
Mutual labels:  redis
Firecamp
Serverless Platform for the stateful services
Stars: ✭ 194 (-1.52%)
Mutual labels:  redis
Back End Interview
后端面试题汇总(Python、Redis、MySQL、PostgreSQL、Kafka、数据结构、算法、编程、网络)
Stars: ✭ 188 (-4.57%)
Mutual labels:  redis
Redis Timeseries
Future development of redis-timeseries is at github.com/RedisLabsModules/redis-timeseries.
Stars: ✭ 197 (+0%)
Mutual labels:  redis
Api
API for Current cases and more stuff about COVID-19 and Influenza
Stars: ✭ 2,323 (+1079.19%)
Mutual labels:  redis
Repoll
Redis管理平台Repoll,现已开源,基于redis3.x,支持单机、哨兵以及集群模式
Stars: ✭ 196 (-0.51%)
Mutual labels:  redis
Redis Roaring
Roaring Bitmaps for Redis
Stars: ✭ 191 (-3.05%)
Mutual labels:  redis
Rediscompare
rediscompare is a tool for chech two redis db data consistency. 是用来对比、校验redis 多个数据库数据一致性的命令行工具,支持单实例到单实例、单实例到原生集群、多实例多库到单实例等场景。
Stars: ✭ 194 (-1.52%)
Mutual labels:  redis
Notorious
Go: A feature-complete, performant torrent tracker
Stars: ✭ 194 (-1.52%)
Mutual labels:  redis
Dailyreport
日报管理系统V1版本,适合小团队的每日汇报记录
Stars: ✭ 191 (-3.05%)
Mutual labels:  redis
Note Gin
【重构中....】🎉📗📝Cloud note file system, supporting MD file batch upload and download and online reading📌 前端:https://github.com/biningo/note-vue
Stars: ✭ 197 (+0%)
Mutual labels:  redis
Webredismanager
WebRedis Manager is a simple management to implement Redis using SAEA. RedisSocket, SAEA.MVC and running speed quickly.WebRedisManager是使用的SAEA.RedisSocket、SAEA.MVC等实现Redis的简便管理功能,轻松运行~
Stars: ✭ 189 (-4.06%)
Mutual labels:  redis
Istio Micro
istio 微服务示例代码 grpc+protobuf+echo+websocket+mysql+redis+kafka+docker-compose
Stars: ✭ 194 (-1.52%)
Mutual labels:  redis
Redis Manager
Redis 一站式管理平台,支持集群的监控、安装、管理、告警以及基本的数据操作
Stars: ✭ 2,646 (+1243.15%)
Mutual labels:  redis
Spring Cloud Azure
Spring Cloud integration with Azure services
Stars: ✭ 197 (+0%)
Mutual labels:  redis
Mudpi Core
Configurable automation library for linux SBC boards including raspberry pi
Stars: ✭ 194 (-1.52%)
Mutual labels:  redis

Ratelimit: Slow your roll

Build Status Code Climate Coverage Status

Ratelimit provides a way to rate limit actions across multiple servers using Redis. This is a port of RateLimit.js found here and inspired by this post.

Installation

Add this line to your application's Gemfile:

gem 'ratelimit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ratelimit

Usage

My example use case is bulk processing data against an external API. This will allow you to limit multiple processes across multiple servers as long as they all use the same Redis database.

Add to the count for a given subject via add with a unique key. I've used the example of a phone number below but anything unique would work (URL, email address, etc.)

You can then fetch the number of executions for given interval in seconds via the count method.

ratelimit = Ratelimit.new("messages")
5.times do
  ratelimit.add(phone_number)
end
ratelimit.count(phone_number, 30)
# => 5

You can check if a given threshold has been exceeded or not. The following code checks if the currently rate is over 10 executions in the last 30 seconds or not.

ratelimit.exceeded?(phone_number, threshold: 10, interval: 30)
# => false
ratelimit.within_bounds?(phone_number, threshold: 10, interval: 30)
# => true

You can also pass a block that will only get executed if the given threshold is within bounds. Beware, this code blocks until the block can be run.

ratelimit.exec_within_threshold phone_number, threshold: 10, interval: 30 do
  some_rate_limited_code
  ratelimit.add(phone_number)
end

Documentation

Full documentation can be found here.

Contributing

  1. Fork it ( https://github.com/ejfinneran/ratelimit/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].