{"id":19652652,"url":"https://github.com/denpeshkov/throttle","last_synced_at":"2026-01-12T01:47:00.017Z","repository":{"id":255658892,"uuid":"847348679","full_name":"denpeshkov/throttle","owner":"denpeshkov","description":"Distributed rate limiter on top of Redis","archived":false,"fork":false,"pushed_at":"2025-07-06T11:51:33.000Z","size":72,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-06T12:42:48.715Z","etag":null,"topics":["limiter","redis"],"latest_commit_sha":null,"homepage":"","language":"Go","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/denpeshkov.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,"zenodo":null}},"created_at":"2024-08-25T15:17:09.000Z","updated_at":"2025-07-06T11:51:30.000Z","dependencies_parsed_at":"2024-11-11T15:11:46.783Z","dependency_job_id":"e121ebc5-e5c9-4b23-963d-d2a2d680f310","html_url":"https://github.com/denpeshkov/throttle","commit_stats":null,"previous_names":["denpeshkov/throttle","denpeshkov/ratelimit"],"tags_count":2,"template":false,"template_full_name":"denpeshkov/go-template","purl":"pkg:github/denpeshkov/throttle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpeshkov%2Fthrottle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpeshkov%2Fthrottle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpeshkov%2Fthrottle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpeshkov%2Fthrottle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denpeshkov","download_url":"https://codeload.github.com/denpeshkov/throttle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpeshkov%2Fthrottle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28331253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"ssl_error","status_checked_at":"2026-01-12T00:36:15.229Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["limiter","redis"],"created_at":"2024-11-11T15:11:38.227Z","updated_at":"2026-01-12T01:47:00.012Z","avatar_url":"https://github.com/denpeshkov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Throttle\n\n[![CI](https://github.com/denpeshkov/throttle/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/denpeshkov/throttle/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/denpeshkov/throttle)](https://goreportcard.com/report/github.com/denpeshkov/throttle)\n[![Go Reference](https://pkg.go.dev/badge/github.com/denpeshkov/throttle.svg)](https://pkg.go.dev/github.com/denpeshkov/throttle)\n\nA Go library that implements a rate limiter using various algorithms, backed by [Redis](https://redis.io).\n\nCurrently implemented rate-limiting algorithms:\n- Sliding Window Log\n- Sliding Window Counter\n- Token Bucket\n\nFor an overview of the pros and cons of different rate-limiting algorithms, you can check out this reference: [How to Design a Scalable Rate Limiting Algorithm with Kong API](https://konghq.com/blog/engineering/how-to-design-a-scalable-rate-limiting-algorithm)\n\n# Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/denpeshkov/throttle\"\n\t\"github.com/redis/go-redis/v9\"\n)\n\n// Redis is a wrapper for the go-redis client, implementing the throttle.Rediser interface.\ntype Redis struct {\n\trdb *redis.Client\n}\n\nfunc (r Redis) ScriptLoad(ctx context.Context, script string) (string, error) {\n\treturn r.rdb.ScriptLoad(ctx, script).Result()\n}\nfunc (r Redis) EvalSHA(ctx context.Context, sha1 string, keys []string, args ...any) (any, error) {\n\treturn r.rdb.EvalSha(ctx, sha1, keys, args...).Result()\n}\nfunc (r Redis) Del(ctx context.Context, keys ...string) (int64, error) {\n\treturn r.rdb.Del(ctx, keys...).Result()\n}\n\nfunc main() {\n\t// Create a Redis client\n\trdb := Redis{\n\t\trdb: redis.NewClient(\u0026redis.Options{Addr: \"localhost:6379\"}),\n\t}\n\n\tlimit := throttle.Limit{\n\t\tEvents:   5,               // Allow 5 requests\n\t\tInterval: 1 * time.Minute, // Per minute\n\t}\n\n\t// Create a Sliding-Window Log rate limiter\n\tlimiter, err := throttle.NewSWLogLimiter(rdb, limit)\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to create limiter: %v\", err)\n\t}\n\n\tconst key = \"user:123\"\n\tstatus, err := limiter.Allow(context.Background(), key)\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to check rate limit: %v\", err)\n\t}\n\n\t// Whether the request was limited.\n\t_ = status.Limited\n\t// The number of requests remaining in the current rate limit window\n\t_ = status.Remaining\n\t// The duration until the next event is permitted.\n\t_ = status.Delay\n}\n```\n# Requirements\n\nThis library requires Redis version 7.4.0 or later.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenpeshkov%2Fthrottle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenpeshkov%2Fthrottle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenpeshkov%2Fthrottle/lists"}