membphis commented on a change in pull request #2340:
URL: https://github.com/apache/apisix/pull/2340#discussion_r502777237



##########
File path: apisix/plugins/limit-count.lua
##########
@@ -119,6 +148,11 @@ local function create_limit_obj(conf)
                                conf.count, conf.time_window, conf)
     end
 
+    if conf.policy == "redis-cluster" then
+        return limit_redis_cluster_new("plugin-" .. plugin_name,
+                               conf.count, conf.time_window, conf)

Review comment:
       bad indentation

##########
File path: apisix/plugins/limit-count.lua
##########
@@ -70,11 +74,36 @@ 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_serv_list = {
+                            type = "array",
+                            minItems = 2,
+                            items = {
+                                type = "object",
+                                properties = {
+                                    redis_host = {type = "string", minLength = 
2},
+                                    redis_port = {type = "integer", minimum = 
1},

Review comment:
       `max` ?

##########
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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do
+        if value['redis_host'] and value['redis_port'] then
+            config.serv_list[key] = {ip = value['redis_host'], port = 
value['redis_port']}
+        end
+    end
+
+
+    local redis_cluster = require "resty.rediscluster"
+    local red_c = redis_cluster:new(config)
+    if not red_c then
+        error("connect to redis cluster fails")
+    end
+
+    return red_c
+end
+
+
+function _M.new(plugin_name, limit, window, conf)
+    assert(limit > 0 and window > 0)
+
+    _M.red_c = new_redis_cluster(conf)

Review comment:
       that is wrong!! a bug, we need to fix it

##########
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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do
+        if value['redis_host'] and value['redis_port'] then
+            config.serv_list[key] = {ip = value['redis_host'], port = 
value['redis_port']}
+        end
+    end
+
+

Review comment:
       only one blank line is required here

##########
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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do
+        if value['redis_host'] and value['redis_port'] then
+            config.serv_list[key] = {ip = value['redis_host'], port = 
value['redis_port']}
+        end
+    end
+
+
+    local redis_cluster = require "resty.rediscluster"
+    local red_c = redis_cluster:new(config)
+    if not red_c then
+        error("connect to redis cluster fails")
+    end
+
+    return red_c
+end
+
+
+function _M.new(plugin_name, limit, window, conf)
+    assert(limit > 0 and window > 0)
+
+    _M.red_c = new_redis_cluster(conf)
+
+    local self = {limit = limit, window = window, conf = conf,
+                  plugin_name = plugin_name}
+    return setmetatable(self, mt)
+
+end
+
+
+function _M.incoming(self, key)
+    local conf = self.conf
+    local red = _M.red_c
+    core.log.info("ttl key: ", key, " timeout: ", conf.redis_timeout)

Review comment:
       ditto

##########
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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do
+        if value['redis_host'] and value['redis_port'] then
+            config.serv_list[key] = {ip = value['redis_host'], port = 
value['redis_port']}
+        end
+    end
+
+
+    local redis_cluster = require "resty.rediscluster"
+    local red_c = redis_cluster:new(config)
+    if not red_c then
+        error("connect to redis cluster fails")
+    end
+
+    return red_c
+end
+
+
+function _M.new(plugin_name, limit, window, conf)
+    assert(limit > 0 and window > 0)
+
+    _M.red_c = new_redis_cluster(conf)
+
+    local self = {limit = limit, window = window, conf = conf,
+                  plugin_name = plugin_name}
+    return setmetatable(self, mt)
+
+end
+
+
+function _M.incoming(self, key)
+    local conf = self.conf

Review comment:
       need to delete this line

##########
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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do

Review comment:
       `value` is a bad 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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do
+        if value['redis_host'] and value['redis_port'] then
+            config.serv_list[key] = {ip = value['redis_host'], port = 
value['redis_port']}

Review comment:
       `value['redis_host']` -> `value.redis_host`

##########
File path: apisix/plugins/limit-count.lua
##########
@@ -70,11 +74,36 @@ 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_serv_list = {
+                            type = "array",
+                            minItems = 2,
+                            items = {
+                                type = "object",
+                                properties = {
+                                    redis_host = {type = "string", minLength = 
2},
+                                    redis_port = {type = "integer", minimum = 
1},

Review comment:
       I think `host`, `port` name style is better

##########
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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do
+        if value['redis_host'] and value['redis_port'] then
+            config.serv_list[key] = {ip = value['redis_host'], port = 
value['redis_port']}
+        end
+    end
+
+
+    local redis_cluster = require "resty.rediscluster"
+    local red_c = redis_cluster:new(config)
+    if not red_c then
+        error("connect to redis cluster fails")
+    end
+
+    return red_c
+end
+
+
+function _M.new(plugin_name, limit, window, conf)
+    assert(limit > 0 and window > 0)
+
+    _M.red_c = new_redis_cluster(conf)
+
+    local self = {limit = limit, window = window, conf = conf,
+                  plugin_name = plugin_name}
+    return setmetatable(self, mt)
+
+end
+
+
+function _M.incoming(self, key)
+    local conf = self.conf
+    local red = _M.red_c

Review comment:
       fix here

##########
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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do
+        if value['redis_host'] and value['redis_port'] then
+            config.serv_list[key] = {ip = value['redis_host'], port = 
value['redis_port']}
+        end
+    end
+
+
+    local redis_cluster = require "resty.rediscluster"
+    local red_c = redis_cluster:new(config)
+    if not red_c then
+        error("connect to redis cluster fails")
+    end
+
+    return red_c

Review comment:
       `red_c` is a bad 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 core = require("apisix.core")
+local resty_lock = require("resty.lock")
+local assert = assert
+local error = error
+local setmetatable = setmetatable
+local tostring = tostring
+local require = require
+local ipairs = ipairs
+
+
+local _M = {version = 0.1}
+
+
+local mt = {
+    __index = _M
+}
+
+-- https://github.com/steve0511/resty-redis-cluster
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-rediscluster",           --rediscluster name
+        enable_slave_read = true,
+        keepalive_timeout = 60000,              --redis connection pool idle 
timeout
+        keepalive_cons = 1000,                  --redis connection pool size
+        connect_timeout = 1000,                 --timeout while connecting
+        send_timeout = 1000,                    --timeout while sending
+        max_redirection = 5,                    --maximum retry attempts for 
redirection
+        max_connection_attempts = 1,            --maximum retry attempts for 
connection
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password --set password while setting auth
+    }
+
+    for key, value in ipairs(conf.redis_serv_list) do

Review comment:
       `key` is a bad name too




----------------------------------------------------------------
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]


Reply via email to