{"id":36418671,"url":"https://github.com/ashwinbhaskar/redisclient-rate-limit","last_synced_at":"2026-01-11T17:01:33.156Z","repository":{"id":57732485,"uuid":"446794786","full_name":"ashwinbhaskar/redisclient-rate-limit","owner":"ashwinbhaskar","description":"A light weight library to rate limit using token bucket algorithm","archived":false,"fork":false,"pushed_at":"2022-10-03T10:00:02.000Z","size":35,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-18T03:39:54.175Z","etag":null,"topics":["cats-effect-3","lua","redis","redis-rate","scala","zio"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashwinbhaskar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-11T11:32:38.000Z","updated_at":"2024-03-30T13:27:29.000Z","dependencies_parsed_at":"2022-09-10T20:31:18.444Z","dependency_job_id":null,"html_url":"https://github.com/ashwinbhaskar/redisclient-rate-limit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ashwinbhaskar/redisclient-rate-limit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinbhaskar%2Fredisclient-rate-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinbhaskar%2Fredisclient-rate-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinbhaskar%2Fredisclient-rate-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinbhaskar%2Fredisclient-rate-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashwinbhaskar","download_url":"https://codeload.github.com/ashwinbhaskar/redisclient-rate-limit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwinbhaskar%2Fredisclient-rate-limit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28314259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cats-effect-3","lua","redis","redis-rate","scala","zio"],"created_at":"2026-01-11T17:01:33.092Z","updated_at":"2026-01-11T17:01:33.147Z","avatar_url":"https://github.com/ashwinbhaskar.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redis Rate Limit ![build](https://github.com/ashwinbhaskar/redisclient-rate-limit/actions/workflows/scala.yml/badge.svg)\nA cats and zio friendly lightweight library that rate limits using token bucket algorithm. The library executes redis commands as `Lua` code which makes the operations atomic. The library internally creates and memoizes a redis client using [scala-redis](https://github.com/debasishg/scala-redis) if redis client is not provided.\n\n## Importing\nAdd the following to your `build.sbt`\n```\nlibraryDependencies =+ \"io.github.ashwinbhaskar\" %% \"redis-rate-limit-ce\" % \"4.0.0\" // If you use cats effect (3.x)\n\nlibraryDependencies =+ \"io.github.ashwinbhaskar\" %% \"redis-rate-limit-zio\" % \"4.0.0\" // If you use zio (2.x)\n\n```\n\n## Usage\n\nLet's take a look at a scenario where we have to rate limit an API call to 5 calls per user in a time window of 5 seconds.\n### ZIO\n\n```scala\nimport zio._\nimport com.redis.RedisClient //From scala-redis library\nimport com.redis.ratelimit._ //This library\n\nval apiCall: RIO[HttpClient, String] = ???\n\nval userId: String = ???\n\n//Externally provided Redis Client\nval redisClient = new RedisClient(\"localhost\", 6379)\n\nval rateLimitedApiCall: RIO[HttpClient with RedisClient, String] = apiCall.withRateLimit(key = userId, maxTokens = 5, timeWindowInSec = 5)\n\n\n// Internally used Redis Client\nval redisHost: String = ???\nval redisPort: Int = ???\nval config = Config(redisHost, redisPort, maxTokens = 5, timeWindowInSec = 5)\n\nval rateLimitedApiCall: RIO[HttpClient, String] = apiCall.withRateLimit(key = userId, config)\n\n```\n\n### Cats Effect\n\n```scala\nimport cats.effect.IO\nimport com.redis.RedisClient //From scala-redis library\nimport com.redis.ratelimit._ //This library\n\n\n//Externally provided Redis Client\nval host: String = ???\nval port: Int = ???\nimplicit val redisClient: RedisClient = new RedisClient(host, port) //pass your own instance of redis client implicitely\nval userId: String = ???\n\nval apiCall: IO[String] = ???\n\nval result: IO[String] = rateLimited[IO, String](apiCall, key = userId, maxTokens = 5, timeWindowInSec = 5)\n\n//Internally Constructed Redis Client\nval redisHost: String = ???\nval redisPort: Int = ???\nimplicit val config = Config(redisHost, redisPort, maxTokens = 5, timeWindowInSec = 5)\nval userId: String = ???\n\nval apiCall: IO[String] = ???\n\nval result: IO[String] = rateLimited[IO, String](apiCall, key = userId) //internally creates a redis client for the implicit config and keeps it in memory\n\nresult.handleErrorWith {\n    case RedisConnectionError(msg) =\u003e ??? \n    case RateLimitExceeded =\u003e ???\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwinbhaskar%2Fredisclient-rate-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashwinbhaskar%2Fredisclient-rate-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwinbhaskar%2Fredisclient-rate-limit/lists"}