{"id":21062446,"url":"https://github.com/rnd-soft/rapidity","last_synced_at":"2025-05-16T02:31:05.377Z","repository":{"id":41167550,"uuid":"508577498","full_name":"RND-SOFT/Rapidity","owner":"RND-SOFT","description":"Simple but fast Redis-backed distributed rate limiter. Allows you to specify time interval and count within to limit distributed operations.","archived":false,"fork":false,"pushed_at":"2023-04-03T15:07:54.000Z","size":32,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-03T18:40:55.903Z","etag":null,"topics":["gem","rate-limiting","redis","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RND-SOFT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-29T06:45:26.000Z","updated_at":"2024-08-15T11:17:39.000Z","dependencies_parsed_at":"2024-11-19T17:44:36.669Z","dependency_job_id":"cb00ea42-c0e8-43ee-b0e1-3f0896fd66a4","html_url":"https://github.com/RND-SOFT/Rapidity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RND-SOFT%2FRapidity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RND-SOFT%2FRapidity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RND-SOFT%2FRapidity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RND-SOFT%2FRapidity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RND-SOFT","download_url":"https://codeload.github.com/RND-SOFT/Rapidity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254455734,"owners_count":22074044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","rate-limiting","redis","ruby"],"created_at":"2024-11-19T17:38:54.505Z","updated_at":"2025-05-16T02:31:05.372Z","avatar_url":"https://github.com/RND-SOFT.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rapidity\n\n[![Gem Version](https://badge.fury.io/rb/rapidity.svg)](https://rubygems.org/gems/rapidity)\n[![Gem](https://img.shields.io/gem/dt/rapidity.svg)](https://rubygems.org/gems/rapidity/versions)\n[![YARD](https://badgen.net/badge/YARD/doc/blue)](http://www.rubydoc.info/gems/rapidity)\n\n[![Coverage](https://lysander.rnds.pro/api/v1/badges/rapidity_coverage.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_coverage.html)\n[![Quality](https://lysander.rnds.pro/api/v1/badges/rapidity_quality.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_quality.html)\n[![Outdated](https://lysander.rnds.pro/api/v1/badges/rapidity_outdated.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_outdated.html)\n[![Vulnerabilities](https://lysander.rnds.pro/api/v1/badges/rapidity_vulnerable.svg)](https://lysander.rnds.pro/api/v1/badges/rapidity_vulnerable.html)\n\nSimple but fast Redis-backed distributed rate limiter. Allows you to specify time interval and count within to limit distributed operations.\n\nFeatures:\n\n- extremly simple\n- free from race condition through LUA scripting\n- fast\n\n[Article(russian) about gem.](https://blog.rnds.pro/029-rapidity/?utm_source=github\u0026utm_medium=repo\u0026utm_campaign=rnds)\n\n## Usage\n\nRapidity has two variants:\n\n- simple `Rapidity::Limiter` to handle single distibuted counter\n- complex `Rapidity::Composer` to handle multiple counters at once\n\n### Single conter with concurrent access\n\n```ruby\npool = ConnectionPool.new(size: 10) do\n  Redis.new(url: ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379'))\nend\n\n# allow no more 10 requests within 5 seconds\nlimiter = Rapidity::Limiter.new(pool, name: 'requests', threshold: 10, interval: 5)\n\nloop do\n  # try to obtain 3 requests at once\n  quota = limiter.obtain(3).times do\n    make_request\n  end\n\n  if quota == 0\n    # no more requests allowed within interval\n    sleep 1\n  end\nend\n\n```\n\n### Multiple counters\n\n```ruby\npool = ConnectionPool.new(size: 10) do\n  Redis.new(url: ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379'))\nend\n\nLIMITS = [\n  { interval: 1, threshold: 2 },        # no more 2 requests per second\n  { interval: 60, threshold: 200 },     # no more 200 requests per minute\n  { interval: 86400, threshold: 10000 } # no more 10k requests per day\n]\n\nlimiter = Rapidity::Composer.new(pool, name: 'requests', limits: LIMITS)\n\nloop do\n  # try to obtain 3 requests at once\n  quota = limiter.obtain(3).times do\n    make_request\n  end\n\n  if quota == 0\n    # no more requests allowed within interval\n    puts limiter.remains # inspect current limits\n    sleep 1\n  end\nend\n```\n\n## Installation\n\nIt's a gem:\n\n```bash\n  gem install rapidity\n```\n\nThere's also the wonders of [the Gemfile](http://bundler.io):\n\n```ruby\n  gem 'rapidity'\n```\n\n## Special Thanks\n\n- [WeTransfer/prorate](https://github.com/WeTransfer/prorate) for LUA-examples\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnd-soft%2Frapidity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frnd-soft%2Frapidity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnd-soft%2Frapidity/lists"}