Skip to content

Commit

Permalink
feat(limit-count): set minLength of redis_cluster_nodes to 1 (#10612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatlinsky authored Dec 11, 2023
1 parent 0bf719e commit c12002e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apisix/plugins/limit-count.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local limit_count = require("apisix.plugins.limit-count.init")

local plugin_name = "limit-count"
local _M = {
version = 0.4,
version = 0.5,
priority = 1002,
name = plugin_name,
schema = limit_count.schema,
Expand Down
2 changes: 1 addition & 1 deletion apisix/plugins/limit-count/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ local policy_to_additional_properties = {
properties = {
redis_cluster_nodes = {
type = "array",
minItems = 2,
minItems = 1,
items = {
type = "string", minLength = 2, maxLength = 100
},
Expand Down
51 changes: 51 additions & 0 deletions t/plugin/limit-count-redis-cluster3.t
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,54 @@ __DATA__
}
--- response_body
remaining: 1
=== TEST 2: set route, with single node in redis_cluster_nodes and redis_cluster_name
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis-cluster",
"redis_timeout": 1001,
"redis_cluster_nodes": [
"127.0.0.1:5000"
],
"redis_cluster_name": "redis-cluster-1"
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 3: up the limit for single node in redis_cluster_nodes
--- pipelined_requests eval
["GET /hello", "GET /hello", "GET /hello"]
--- error_code eval
[200, 200, 503]

0 comments on commit c12002e

Please sign in to comment.