openresty / lua-resty-redis

Lua redis client driver for the ngx_lua based on the cosocket API
1.91k stars 448 forks source link

redis:connect is taking exactly 60 seconds for connection #253

Closed dsnr-coder closed 2 years ago

dsnr-coder commented 2 years ago

Hi,

I have created below util method for redis write connection, this method will be used by 4 plugins to get redis write connection. For ingress api /login - defined plugins plugin1, plugin2, plugin3, plugin4 On hitting /login api, all 4 plugins will get triggered one after the other. Out of the 4 plugins for 3 plugins redis:connect is returning the connection immediately but for the 4th plugin, redis:connect is taking exactly 60 seconds to return the connection. Could you please help me to understand as why 4th plugin is taking exactly 60 seconds, I tried multiple things but not able to find root cause..

local redis = require "resty.redis"
function _M.get_redis_write_connection()
    local redisPassword = "test123"
    local redis = redis:new()
    redis:set_timeout(1000000)
    local ok, err = redis:connect(redis-master-0, 6379)
    if not ok then
        kong.log.err("Redis failed to connect::::::: ", err)
    else
        kong.log.info("Redis Successfully connected :::::::: ", ok)
    end
    local res, err = redis:auth(redisPassword)
    if not res then
        kong.log.err("failed to authenticate for write conncetion: ", err)
    else
        kong.log.debug("Successfully authenticated with redis write connection:::::::: ", res)
    end
    return redis        
end

In plugin 4, get_redis_write_connection method is invoked thrice, only very first time, redis:connect is taking 60 seconds to return connection but for the next 2 calls redis:connect is returning the connection within sec..

Any help would be greatly appreciated..