theweakgod commented on code in PR #10866:
URL: https://github.com/apache/apisix/pull/10866#discussion_r1469346322
##########
apisix/plugins/limit-conn/limit-conn-redis-cluster.lua:
##########
@@ -0,0 +1,158 @@
+local rediscluster = require("resty.rediscluster")
+local core = require("apisix.core")
+local assert = assert
+local setmetatable = setmetatable
+local math = require "math"
+local floor = math.floor
+local ipairs = ipairs
+local ngx_timer_at = ngx.timer.at
+
+local _M = {version = 0.1}
+
+
+local mt = {
+ __index = _M
+}
+
+
+local function new_redis_cluster(conf)
+ local config = {
+ name = conf.redis_cluster_name,
+ serv_list = {},
+ read_timeout = conf.redis_timeout,
+ auth = conf.redis_password,
+ dict_name = "plugin-limit-conn-redis-cluster-slot-lock",
+ connect_opts = {
+ ssl = conf.redis_cluster_ssl,
+ ssl_verify = conf.redis_cluster_ssl_verify,
+ }
+ }
+
+ 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, conf, max, burst, default_conn_delay)
+ local self = {
+ conf = conf,
+ plugin_name = plugin_name,
+ burst = burst,
+ max = max + 0, -- just to ensure the param is good
+ unit_delay = default_conn_delay,
+ }
+ return setmetatable(self, mt)
+end
+
+
+function _M.incoming(self, key, commit)
+ local max = self.max
+
+ -- init redis
+ local conf = self.conf
+ local red, err = new_redis_cluster(conf)
Review Comment:
OK
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]