{"id":15356626,"url":"https://github.com/adlered/simplecurrentlimiter","last_synced_at":"2025-04-04T17:23:25.952Z","repository":{"id":105570642,"uuid":"214340959","full_name":"adlered/SimpleCurrentLimiter","owner":"adlered","description":":robot: 小轮子 | 简单限流器 | IP地址/任意字符串指定时间内限制 | 对字符串在时间内执行次数记录并判断返回令牌 | Simple current limiter | IP address / Any string specified time limit | Record the number of executions of the string in time and judge the return token","archived":false,"fork":false,"pushed_at":"2019-10-11T04:39:53.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T08:23:54.674Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/adlered.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,"governance":null}},"created_at":"2019-10-11T04:07:12.000Z","updated_at":"2021-12-02T07:39:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec3f836e-be12-4a5e-8e28-075fa25689ed","html_url":"https://github.com/adlered/SimpleCurrentLimiter","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"4fd22232217d9d3c9fe07fc5c584bd02ef2f74e9"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adlered%2FSimpleCurrentLimiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adlered%2FSimpleCurrentLimiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adlered%2FSimpleCurrentLimiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adlered%2FSimpleCurrentLimiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adlered","download_url":"https://codeload.github.com/adlered/SimpleCurrentLimiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247218015,"owners_count":20903186,"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-10-01T12:29:23.557Z","updated_at":"2025-04-04T17:23:25.927Z","avatar_url":"https://github.com/adlered.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"### [English README](#English)\n\n## 获得帮助\n\n:construction_worker: 如果你对该项目的使用有无法解决的疑问，欢迎向我提问。请在我的资料中找到联系方式，我会及时回复。\n\n## SimpleCurrentLimit\n\nSimpleCurrentLimit可以指定：\n\n在`X`秒内，同字符串只允许访问`Y`次。\n\n通常用于WEB项目，IP地址就是一串字符串\n\n首先，从[这里](https://github.com/AdlerED/SimpleCurrentLimiter/releases)下载最新的Jar包，并引入到你的项目中。\n\n假设，我们设置每个IP地址（或任意字符串）在2秒内只能访问1次，实例化SimpleCurrentLimit代码如下：\n\n```\n// 在实例化时指定2秒内只能访问1次\nSimpleCurrentLimiter simpleCurrentLimiter = new SimpleCurrentLimiter(2, 1);\n```\n\n那么如何实现对IP地址的控制呢？\n\n每次该IP地址（或任意字符串）访问时，调用SimpleCurrentLimiter的`access(String str)`方法：\n\n```\nboolean result;\nresult = simpleCurrentLimiter.access(\"127.0.0.1\");\nSystem.out.println(\"IP Access: 127.0.0.1, passed: \" + result);\n```\n\n`access(String str)`方法传入字符串，并返回Boolean值，为false时，说明该字符串已超出限制，为true时代表该字符串允许通过。\n\n### 实例测试：\n\n```\ntry {\n    SimpleCurrentLimiter simpleCurrentLimiter = new SimpleCurrentLimiter(2, 1);\n    boolean result;\n    result = simpleCurrentLimiter.access(\"127.0.0.1\");\n    System.out.println(\"IP Access: 127.0.0.1, passed: \" + result);\n    Thread.sleep(500);\n    result = simpleCurrentLimiter.access(\"1.1.1.1\");\n    System.out.println(\"IP Access: 1.1.1.1, passed: \" + result);\n    Thread.sleep(500);\n    result = simpleCurrentLimiter.access(\"127.0.0.1\");\n    System.out.println(\"IP Access: 127.0.0.1, passed: \" + result);\n    Thread.sleep(500);\n} catch (InterruptedException IE) {}\n```\n\n返回结果：\n\n```\nIP Access: 127.0.0.1, passed: true\nIP Access: 1.1.1.1, passed: true\nIP Access: 127.0.0.1, passed: false\n```\n\n`127.0.0.1`在2秒内访问了2次，第一次返回`true`即通过，第二次会被拒绝，返回`false`。\n\n`1.1.1.1`在2秒内只有1次访问，所以直接返回`true`。\n\n# English\n\n## Getting help\n\n:construction_worker: If you have any questions about the use of this project, please feel free to ask me questions. Please find the contact information in my profile and I will respond promptly.\n\n## SimpleCurrentLimit\n\nSimpleCurrentLimit can specify:\n\nWithin `X` seconds, the same string is only allowed to access `Y` times.\n\nUsually used for WEB projects, the IP address is a string of strings\n\nFirst, download the latest Jar package from [here] (https://github.com/AdlerED/SimpleCurrentLimiter/releases) and import it into your project.\n\nAssume that we set each IP address (or any string) to be accessed only once in 2 seconds. Instantiate the SimpleCurrentLimit code as follows:\n\n```\n// can only be accessed once within 2 seconds when instantiating\nSimpleCurrentLimiter simpleCurrentLimiter = new SimpleCurrentLimiter(2, 1);\n```\n\nSo how do you implement control over IP addresses?\n\nEach time the IP address (or any string) is accessed, the SimpleCurrentLimiter's `access(String str)` method is called:\n\n```\nboolean result;\nresult = simpleCurrentLimiter.access(\"127.0.0.1\");\nSystem.out.println(\"IP Access: 127.0.0.1, passed: \" + result);\n```\n\nThe `access(String str)` method passes in a string and returns a Boolean value. When it is false, it indicates that the string has exceeded the limit. When true, it means that the string is allowed to pass.\n\n### Instance test:\n\n```\ntry {\n    SimpleCurrentLimiter simpleCurrentLimiter = new SimpleCurrentLimiter(2, 1);\n    boolean result;\n    result = simpleCurrentLimiter.access(\"127.0.0.1\");\n    System.out.println(\"IP Access: 127.0.0.1, passed: \" + result);\n    Thread.sleep(500);\n    result = simpleCurrentLimiter.access(\"1.1.1.1\");\n    System.out.println(\"IP Access: 1.1.1.1, passed: \" + result);\n    Thread.sleep(500);\n    result = simpleCurrentLimiter.access(\"127.0.0.1\");\n    System.out.println(\"IP Access: 127.0.0.1, passed: \" + result);\n    Thread.sleep(500);\n} catch (InterruptedException IE) {}\n```\n\nReturn results:\n\n```\nIP Access: 127.0.0.1, passed: true\nIP Access: 1.1.1.1, passed: true\nIP Access: 127.0.0.1, passed: false\n```\n\n`127.0.0.1` has been accessed 2 times in 2 seconds, the first time to return `true` is passed, the second time will be rejected, return `false`.\n\n`1.1.1.1` has only 1 access in 2 seconds, so return `true` directly.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadlered%2Fsimplecurrentlimiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadlered%2Fsimplecurrentlimiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadlered%2Fsimplecurrentlimiter/lists"}