juzhiyuan commented on a change in pull request #2340:
URL: https://github.com/apache/apisix/pull/2340#discussion_r502799124
##########
File path: apisix/plugins/limit-count.lua
##########
@@ -70,11 +74,29 @@ local schema = {
type = "string", minLength = 0,
},
redis_timeout = {
- type = "integer", minimum = 1,
- default = 1000,
+ type = "integer", minimum = 1, default = 1000,
},
},
required = {"redis_host"},
+ },
+ {
+ properties = {
+ policy = {
+ enum = {"redis-cluster"},
+ },
+ redis_cluster_nodes = {
+ type = "array",
+ minItems = 2,
+ items = {type = "string", minLength = 2, maxLength
= 100},
Review comment:
Looks like we need format those codes to have a uniform code style?
##########
File path: apisix/plugins/limit-count.lua
##########
@@ -70,11 +74,29 @@ local schema = {
type = "string", minLength = 0,
},
redis_timeout = {
- type = "integer", minimum = 1,
- default = 1000,
+ type = "integer", minimum = 1, default = 1000,
},
},
required = {"redis_host"},
+ },
+ {
+ properties = {
+ policy = {
+ enum = {"redis-cluster"},
Review comment:
@liuhengloveyou Because this plugin would be shown by UI components on
the frontend, could you please have a test on this site[1] using this new
schema? or could you please provide the full JSON Schema for this plugin then
paste here? I could have a try myself.
[1] https://rjsf-team.github.io/react-jsonschema-form/
##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -0,0 +1,141 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local rediscluster = require("resty.rediscluster")
+local core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local ipairs = ipairs
+
+local _M = {}
+
+local mt = {
+ __index = _M
+}
+
+
+local function split(inputstr, sep)
+ if sep == nil then
+ sep = "%s"
+ end
+
+ local t={}
+ for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+ table.insert(t, str)
+ end
+
+ return t
+ end
+
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+ local config = {
+ name = "apisix-rediscluster",
+ serv_list = {},
+ read_timeout = conf.redis_timeout,
+ auth = conf.redis_password
+ }
+
+ for i, conf_item in ipairs(conf.redis_cluster_nodes) do
+ local ip, port = split(conf_item, ":")
+ config.serv_list[i] = {ip = ip, port = port}
+ end
+
+ local red_cli = rediscluster:new(config)
+ if not red_cli then
+ error("limit-count-redis: connect to redis cluster fails")
Review comment:
failed
##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -0,0 +1,141 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local rediscluster = require("resty.rediscluster")
+local core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local ipairs = ipairs
+
+local _M = {}
+
+local mt = {
+ __index = _M
+}
+
+
+local function split(inputstr, sep)
+ if sep == nil then
+ sep = "%s"
+ end
+
+ local t={}
+ for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+ table.insert(t, str)
+ end
+
+ return t
+ end
+
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+ local config = {
+ name = "apisix-rediscluster",
Review comment:

Should we use a uniform name?
##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -0,0 +1,141 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local rediscluster = require("resty.rediscluster")
+local core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local ipairs = ipairs
+
+local _M = {}
+
+local mt = {
+ __index = _M
+}
+
+
+local function split(inputstr, sep)
+ if sep == nil then
+ sep = "%s"
+ end
+
+ local t={}
Review comment:
Would better add 2 spaces around the `=`.
##########
File path: doc/plugins/limit-count.md
##########
@@ -39,11 +39,12 @@ Limit request rate by a fixed number of requests in a given
time window.
| time_window | integer | required | | [0,...]
| the time window in
seconds before the request count is reset.
|
| key | string | required | | ["remote_addr",
"server_addr", "http_x_real_ip", "http_x_forwarded_for"] | the user specified
key to limit the rate.
|
| rejected_code | integer | optional | 503 | [200,600]
| The HTTP status code
returned when the request exceeds the threshold is rejected, default 503.
|
-| policy | string | optional | "local" | ["local",
"redis"] | The
rate-limiting policies to use for retrieving and incrementing the limits.
Available values are `local`(the counters will be stored locally in-memory on
the node) and `redis`(counters are stored on a Redis server and will be shared
across the nodes, usually used it to do the global speed limit). |
+| policy | string | optional | "local" | ["local",
"redis", "redis-cluster"]
| The rate-limiting policies to use for retrieving and incrementing the limits.
Available values are `local`(the counters will be stored locally in-memory on
the node) and `redis`(counters are stored on a Redis server and will be shared
across the nodes, usually used it to do the global speed limit). |
Review comment:
usually **use** it to xxx
##########
File path: doc/plugins/limit-count.md
##########
@@ -39,11 +39,12 @@ Limit request rate by a fixed number of requests in a given
time window.
| time_window | integer | required | | [0,...]
| the time window in
seconds before the request count is reset.
|
| key | string | required | | ["remote_addr",
"server_addr", "http_x_real_ip", "http_x_forwarded_for"] | the user specified
key to limit the rate.
|
| rejected_code | integer | optional | 503 | [200,600]
| The HTTP status code
returned when the request exceeds the threshold is rejected, default 503.
|
-| policy | string | optional | "local" | ["local",
"redis"] | The
rate-limiting policies to use for retrieving and incrementing the limits.
Available values are `local`(the counters will be stored locally in-memory on
the node) and `redis`(counters are stored on a Redis server and will be shared
across the nodes, usually used it to do the global speed limit). |
+| policy | string | optional | "local" | ["local",
"redis", "redis-cluster"]
| The rate-limiting policies to use for retrieving and incrementing the limits.
Available values are `local`(the counters will be stored locally in-memory on
the node) and `redis`(counters are stored on a Redis server and will be shared
across the nodes, usually used it to do the global speed limit). |
| redis_host | string | required for `redis` | |
| When using the
`redis` policy, this property specifies the address of the Redis server.
|
| redis_port | integer | optional | 6379 | [1,...]
| When using the
`redis` policy, this property specifies the port of the Redis server.
|
| redis_password | string | optional | |
| When using the
`redis` policy, this property specifies the password of the Redis server.
|
| redis_timeout | integer | optional | 1000 | [1,...]
| When using the
`redis` policy, this property specifies the timeout in milliseconds of any
command submitted to the Redis server.
|
+| redis_serv_list | array | optional | |
| When using `redis-cluster` policy,This
property is a list of addresses of Redis cluster service nodes. |
Review comment:
Just have a try on the `Grammarly` extension (Chrome).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]