From 32709aaac610af7acda709d6c316f8ac2ea2289e Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 11 Apr 2022 09:10:48 +0800 Subject: [PATCH] fix(plugin/rate-limiting) correctly handle `config.redis_database` Use the default connection pool if `config.redis_database` is `0`. --- kong/plugins/rate-limiting/policies/init.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kong/plugins/rate-limiting/policies/init.lua b/kong/plugins/rate-limiting/policies/init.lua index 4b327dccc334..735440323c75 100644 --- a/kong/plugins/rate-limiting/policies/init.lua +++ b/kong/plugins/rate-limiting/policies/init.lua @@ -61,9 +61,13 @@ local function get_redis_connection(conf) -- use a special pool name only if redis_database is set to non-zero -- otherwise use the default pool name host:port - sock_opts.pool = conf.redis_database and - conf.redis_host .. ":" .. conf.redis_port .. - ":" .. conf.redis_database + if conf.redis_database ~= 0 then + sock_opts.pool = fmt( "%s:%d;%d", + conf.redis_host, + conf.redis_port, + conf.redis_database) + end + local ok, err = red:connect(conf.redis_host, conf.redis_port, sock_opts) if not ok then