Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
theweakgod committed Feb 2, 2024
1 parent 6f2e324 commit ffb0d77
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions apisix/plugins/limit-conn/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ local _M = {version = 0.3}
function _M.incoming(self, red, key, commit)
local max = self.max
self.committed = false
local hash_key = "limit_conn"
key = "limit_conn"

local conn, err
if commit then
conn, err = red:incrby(hash_key .. ":" .. key, 1)
conn, err = red:incrby(key, 1)
if not conn then
return nil, err
end

if conn > max + self.burst then
conn, err = red:incrby(hash_key .. ":" .. key, -1)
conn, err = red:incrby(key, -1)
if not conn then
return nil, err
end
Expand All @@ -43,7 +43,7 @@ function _M.incoming(self, red, key, commit)
self.committed = true

else
local conn_from_red, err = red:get(hash_key .. ":" .. key)
local conn_from_red, err = red:get(key)
if err then
return nil, err
end
Expand All @@ -63,9 +63,9 @@ end

function _M.leaving(self, red, key, req_latency)
assert(key)
local hash_key = "limit_conn"
key = "limit_conn" .. ":" .. key

local conn, err = red:incrby(hash_key .. ":" .. key, -1)
local conn, err = red:incrby(key, -1)
if not conn then
return nil, err
end
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/plugins/limit-conn.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The `limit-conn` Plugin limits the number of concurrent requests to your service
| rejected_code | string | False | 503 | [200,...,599] | HTTP status code returned when the requests exceeding the threshold are rejected. |
| rejected_msg | string | False | | non-empty | Body of the response returned when the requests exceeding the threshold are rejected. |
| allow_degradation | boolean | False | false | | When set to `true` enables Plugin degradation when the Plugin is temporarily unavailable and allows requests to continue. |
| policy | string | False | local | local, redis, redis-cluster | counter type to choose local, redis or redis-cluster |
| policy | string | False | "local" | ["local", "redis", "redis-cluster"] | Rate-limiting policies to use for retrieving and increment the limit count. When set to `local` the counters will be locally stored in memory on the node. When set to `redis` counters are stored on a Redis server and will be shared across the nodes. It is done usually for global speed limiting, and setting to `redis-cluster` uses a Redis cluster instead of a single instance. |
| redis_host | string | required when `policy` is `redis` | | | Address of the Redis server. Used when the `policy` attribute is set to `redis`. |
| redis_port | integer | False | 6379 | [1,...] | Port of the Redis server. Used when the `policy` attribute is set to `redis`. |
| redis_username | string | False | | | Username for Redis authentication if Redis ACL is used (for Redis version >= 6.0). If you use the legacy authentication method `requirepass` to configure Redis password, configure only the `redis_password`. Used when the `policy` is set to `redis`. |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/plugins/limit-conn.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ description: 本文介绍了 Apache APISIX limit-conn 插件的相关操作,
| rejected_code | string || 503 | [200,...,599] | 当请求数超过 `conn` + `burst` 阈值时,返回的 HTTP 状态码。 |
| rejected_msg | string || | 非空 | 当请求数超过 `conn` + `burst` 阈值时,返回的信息。 |
| allow_degradation | boolean || false | | 当设置为 `true` 时,启用插件降级并自动允许请求继续。 |
| policy | string | | local | local, redis, redis-cluster | 计数器类型 |
| policy | string || "local" | ["local", "redis", "redis-cluster"] | 用于检索和增加限制计数的策略。当设置为 `local` 时,计数器被以内存方式保存在节点本地;当设置为 `redis` 时,计数器保存在 Redis 服务节点上,从而可以跨节点共享结果,通常用它来完成全局限速;当设置为 `redis-cluster` 时,使用 Redis 集群而不是单个实例。|
| redis_host | string || | | 当使用 `redis` 限速策略时,Redis 服务节点的地址。**`policy` 属性设置为 `redis` 时必选。** |
| redis_port | integer || 6379 | [1,...] | 当使用 `redis` 限速策略时,Redis 服务节点的端口。 |
| redis_username | string || | | 若使用 Redis ACL 进行身份验证(适用于 Redis 版本 >=6.0),则需要提供 Redis 用户名。若使用 Redis legacy 方式 `requirepass` 进行身份验证,则只需将密码配置在 `redis_password`。当 `policy` 设置为 `redis` 时使用。 |
Expand Down

0 comments on commit ffb0d77

Please sign in to comment.