Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(limit-count): supported global limit count with redis server. #624

Merged
merged 9 commits into from
Oct 8, 2019
31 changes: 31 additions & 0 deletions doc/plugins/limit-count-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
然后在 route 页面中添加 limit-count 插件:
![](../images/plugin/limit-count-2.png)

如果你需要一个集群级别的流量控制,我们可以借助 redis server 来完成。不同的 APISIX 节点之间将共享流量限速结果,实现集群流量限速。

请看下面例子:

```shell
curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"uri": "/index.html",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis",
"redis": {
"host": "127.0.0.1",
"port": 6379,
"timeout": 1001
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"39.97.63.215:80": 1
}
}
}'
```

#### 测试插件
上述配置限制了 60 秒内只能访问 2 次,前两次访问都会正常访问:
```shell
Expand Down
32 changes: 32 additions & 0 deletions doc/plugins/limit-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### example

#### enable plugin

Here's an example, enable the `limit count` plugin on the specified route:

```shell
Expand Down Expand Up @@ -47,6 +48,37 @@ You can open dashboard with a browser: `http://127.0.0.1:9080/apisix/dashboard/`
Then add limit-count plugin:
![](../images/plugin/limit-count-2.png)

If you need a cluster-level precision traffic limit, then we can do it with the redis server. The rate limit of the traffic will be shared between different APISIX nodes to limit the rate of cluster traffic.

Here is the example:

```shell
curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"uri": "/index.html",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis",
"redis": {
"host": "127.0.0.1",
"port": 6379,
"timeout": 1001
membphis marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"39.97.63.215:80": 1
}
}
}'
```

#### test plugin
The above configuration limits access to only 2 times in 60 seconds. The first two visits will be normally:
```shell
Expand Down