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 set_keepalive doesn't work #268

Open ebony0319 opened 1 year ago

ebony0319 commented 1 year ago

I am writing a test to test the performance of reids. The following is my test code. I used 2000 threads to test,and listen to the tcp connection of redis. That connection pool doesn't seem to work very well, is it my code problem?

http {
    server {
        listen 80;

        location /redis {
            content_by_lua_block {
                local resty_redis = require "resty.redis"
                local redis = resty_redis:new()

                local ok, err = redis:connect("127.0.0.1", 6379)
                if not ok then
                    ngx.say("Failed to connect to Redis: ", err)
                    return
                end

                local res, err = redis:auth("r-xxxxx")
                if not res then
                    ngx.say("Failed to authenticate with Redis: ", err)
                    return
                end

                local key = "test"
                local value, err = redis:get(key)
                if not value then
                    ngx.say("Failed to get key from Redis: ", err)
                else
                    ngx.say("Value of key ", key, ": ", value)
                end

                redis:set_keepalive(100000, 1000)
            }
        }
    }
}
zhuizhuhaomeng commented 1 year ago

What information are you basing this on to determine that keepalive is not working?