{"id":19308603,"url":"https://github.com/sparkinzy/redis-limiter","last_synced_at":"2025-10-30T20:17:00.739Z","repository":{"id":57021666,"uuid":"201201542","full_name":"Sparkinzy/redis-limiter","owner":"Sparkinzy","description":"基于redis的限流器","archived":false,"fork":false,"pushed_at":"2019-08-08T07:40:16.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-06T01:29:38.956Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/Sparkinzy.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":"2019-08-08T07:18:58.000Z","updated_at":"2019-08-08T07:40:18.000Z","dependencies_parsed_at":"2022-08-23T12:20:41.905Z","dependency_job_id":null,"html_url":"https://github.com/Sparkinzy/redis-limiter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sparkinzy%2Fredis-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sparkinzy%2Fredis-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sparkinzy%2Fredis-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sparkinzy%2Fredis-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sparkinzy","download_url":"https://codeload.github.com/Sparkinzy/redis-limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240409852,"owners_count":19796797,"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":[],"created_at":"2024-11-10T00:15:40.327Z","updated_at":"2025-10-30T20:16:55.680Z","avatar_url":"https://github.com/Sparkinzy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 使用方式\n\n## 添加redis配置\n```php\n$redisConf = [\n\t'host' =\u003e '127.0.0.1',\n\t'port' =\u003e 16379,\n\t'auth' =\u003e ''\n];\nLimit::setRedisConf($redisConf);\n```\n\n## 配置限流规则\n```php\nLimit::getInstance()-\u003eaddItem('default')-\u003esetMax('1r/s');\n```\naddItem() 配置的是限流的key\n\nsetMax()  配置的是限流规则，类似nginx限流规则\n- 1r/s 表示每秒限一次\n- 1r/m 每分钟一次\n- 1r/h 每小时一次\n- 1r/d 每天一次\n\n## 3.实际项目中检查是否符合限流\n```php\nif (Limit::isAllow('default')){\n    echo '成功',PHP_EOL;\n}else{\n    echo '失败',PHP_EOL;\n}\n```\n\n\n# 完整demo\n```bash\nrequire_once __DIR__.'/vendor/autoload.php';\nuse Mu\\Juyuan\\Limit;\n$redisConf = [\n\t'host' =\u003e '127.0.0.1',\n\t'port' =\u003e 16379,\n\t'auth' =\u003e ''\n];\nLimit::setRedisConf($redisConf);\nLimit::getInstance()-\u003eaddItem('default')-\u003esetMax('1r/s');\nfor ($i=0;$i\u003c100;$i++){\n\tusleep(500000);\n\techo '['.date('Y-m-d H:i:s').']';\n\tif (Limit::isAllow('default')){\n\t\techo '成功',PHP_EOL;\n\t}else{\n\t\techo '失败',PHP_EOL;\n\t}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkinzy%2Fredis-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsparkinzy%2Fredis-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkinzy%2Fredis-limiter/lists"}