You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/10/14 06:05:09 UTC

[GitHub] [apisix] membphis commented on a change in pull request #2406: feature: plugin `limit-count` support to use `redis` cluster

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



##########
File path: apisix/plugins/limit-count/limit-count-redis-cluster.lua
##########
@@ -0,0 +1,134 @@
+--
+-- 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 setmetatable = setmetatable
+local tostring = tostring
+local ipairs = ipairs
+
+local _M = {}
+
+
+local mt = {
+    __index = _M
+}
+
+
+local function new_redis_cluster(conf)
+    local config = {
+        name = "apisix-redis-cluster",
+        serv_list = {},
+        read_timeout = conf.redis_timeout,
+        auth = conf.redis_password,
+        dict_name = "plugin-limit-count-redis-cluster-slot-lock",
+    }
+
+    for i, conf_item in ipairs(conf.redis_cluster_nodes) do
+        local host, port, err = core.utils.parse_addr(conf_item)
+        if err then
+            return nil, "failed to parse address: " .. conf_item
+                        .. " err: " .. err
+        end
+
+        config.serv_list[i] = {ip = host, port = port}
+    end
+
+    local red_cli, err = rediscluster:new(config)
+    if not red_cli then
+        return nil, "failed to new redis cluster: " .. err
+    end
+
+    return red_cli
+end
+
+
+function _M.new(plugin_name, limit, window, conf)
+    local red_cli, err = new_redis_cluster(conf)
+    if not red_cli then
+        return nil, err
+    end
+
+    local self = {
+        limit = limit, window = window, conf = conf,
+        plugin_name = plugin_name, red_cli =red_cli
+    }
+
+    return setmetatable(self, mt)
+end
+
+

Review comment:
       in `limit-count-redis`, the main process of `incoming` is `connect` -> `process` -> `keepalive`.
   
   but in `limit-count-redis-cluster`, the main process of `incoming`is only the `process` . they were different.
   
   I think it is acceptable for those copied code.
   




----------------------------------------------------------------
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:
users@infra.apache.org