diff --git a/apisix/plugins/limit-count.lua b/apisix/plugins/limit-count.lua index 72ab574df775..3e2443d0eade 100644 --- a/apisix/plugins/limit-count.lua +++ b/apisix/plugins/limit-count.lua @@ -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, diff --git a/apisix/plugins/limit-count/init.lua b/apisix/plugins/limit-count/init.lua index a280592b90f5..049e238e916a 100644 --- a/apisix/plugins/limit-count/init.lua +++ b/apisix/plugins/limit-count/init.lua @@ -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 }, diff --git a/t/plugin/limit-count-redis-cluster3.t b/t/plugin/limit-count-redis-cluster3.t index b534c3a2c363..017c3048e675 100644 --- a/t/plugin/limit-count-redis-cluster3.t +++ b/t/plugin/limit-count-redis-cluster3.t @@ -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]