{"id":19763059,"url":"https://github.com/exhammer/hammer-backend-redis","last_synced_at":"2025-05-15T22:12:11.731Z","repository":{"id":23419585,"uuid":"94931822","full_name":"ExHammer/hammer-backend-redis","owner":"ExHammer","description":"A Redis backend for for the Hammer rate-limiter","archived":false,"fork":false,"pushed_at":"2025-05-12T06:54:35.000Z","size":192,"stargazers_count":51,"open_issues_count":3,"forks_count":31,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-15T22:11:44.911Z","etag":null,"topics":["elixir","elixir-lang","phoenix","phoenix-framework","rate-limiter","rate-limiting","redis"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/ExHammer/hammer-backend-redis","language":"Elixir","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/ExHammer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2017-06-20T20:22:51.000Z","updated_at":"2025-04-14T03:46:17.000Z","dependencies_parsed_at":"2023-02-17T00:01:37.674Z","dependency_job_id":"7d84cd93-fdd8-4c63-8130-159a6021fb79","html_url":"https://github.com/ExHammer/hammer-backend-redis","commit_stats":{"total_commits":155,"total_committers":10,"mean_commits":15.5,"dds":0.3096774193548387,"last_synced_commit":"864469117cb8de179dfe5b49a5da745e3eb185fb"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExHammer%2Fhammer-backend-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExHammer%2Fhammer-backend-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExHammer%2Fhammer-backend-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExHammer%2Fhammer-backend-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExHammer","download_url":"https://codeload.github.com/ExHammer/hammer-backend-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430335,"owners_count":22069909,"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":["elixir","elixir-lang","phoenix","phoenix-framework","rate-limiter","rate-limiting","redis"],"created_at":"2024-11-12T04:07:53.799Z","updated_at":"2025-05-15T22:12:06.721Z","avatar_url":"https://github.com/ExHammer.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hammer.Redis\n\n[![Build Status](https://github.com/ExHammer/hammer-backend-redis/actions/workflows/ci.yml/badge.svg)](https://github.com/ExHammer/hammer-backend-redis/actions/workflows/ci.yml)\n[![Hex.pm](https://img.shields.io/hexpm/v/hammer_backend_redis.svg)](https://hex.pm/packages/hammer_backend_redis)\n[![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/hammer_backend_redis)\n[![Total Download](https://img.shields.io/hexpm/dt/hammer_backend_redis.svg)](https://hex.pm/packages/hammer_backend_redis)\n[![License](https://img.shields.io/hexpm/l/hammer_backend_redis.svg)](https://github.com/ExHammer/hammer-backend-redis/blob/master/LICENSE.md)\n\nA Redis backend for the [Hammer](https://github.com/ExHammer/hammer) rate-limiter.\n\nThis backend is a thin [Redix](https://hex.pm/packages/redix) wrapper. A single connection is used per rate-limiter. It should be enough for most use-cases since packets for rate limiting requests are short (i.e. no head of line blocking) and Redis is OK with [pipelining](https://redis.io/learn/operate/redis-at-scale/talking-to-redis/client-performance-improvements#pipelining) (i.e. we don't block awaiting replies). Consider benchmarking before introducing more connections since TCP performance might be unintuitive. For possible pooling approaches, see Redix docs on [pooling](https://hexdocs.pm/redix/real-world-usage.html#name-based-pool) and also [PartitionSupervisor.](https://hexdocs.pm/elixir/1.17.3/PartitionSupervisor.html) Do not use poolboy or db_connection-like pools since they practically disable pipelining which leads to worse connection utilisation and worse performance.\n\nThe algorithm we are using is the first method described (called \"bucketing\") in [Rate Limiting with Redis](https://youtu.be/CRGPbCbRTHA?t=753).\nIn other sources it's sometimes called a \"fixed window counter\".\n\n**TODO:** document ttl issues if servers are misconfigured\n\n## Installation\n\nHammer-backend-redis\nis [available in Hex](https://hex.pm/packages/hammer_backend_redis), the package\ncan be installed by adding `hammer_backend_redis` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:hammer_backend_redis, \"~\u003e 7.0\"}\n  ]\nend\n```\n\n## Usage\n\nDefine the rate limiter:\n\n```elixir\ndefmodule MyApp.RateLimit do\n  use Hammer, backend: Hammer.Redis\nend\n```\n\nAnd add it to your app's supervision tree:\n\n```elixir\nchildren = [\n  {MyApp.RateLimit, url: \"redis://localhost:6379\"}\n]\n```\n\nAnd that's it, calls to `MyApp.RateLimit.hit/3` and so on will use Redis to store\nthe rate-limit counters. See the [documentation](https://hexdocs.pm/hammer_backend_redis/Hammer.Redis.html) for more details.\n\n## Run tests locally\n\nYou need a running Redis instance. One can be started locally using `docker compose up -d redis`.\nSee the [compose.yml](./compose.yml) for more details.\n\n## Getting Help\n\nIf you're having trouble, open an issue on this repo.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexhammer%2Fhammer-backend-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexhammer%2Fhammer-backend-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexhammer%2Fhammer-backend-redis/lists"}