lua-resty-redis icon indicating copy to clipboard operation
lua-resty-redis copied to clipboard

redis set_keepalive doesn't work

Open ebony0319 opened this issue 2 years ago • 1 comments
trafficstars

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)
            }
        }
    }
}

ebony0319 avatar Aug 31 '23 11:08 ebony0319