openresty / lua-resty-redis

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

How to create a single redis connection #261

Open first-mine opened 1 year ago

first-mine commented 1 year ago

I have tried creating a connection with pool_size = 1 and backlog=10 but every concurrent request creating new connection.

For 5 concurrent request this is the output. netstat | grep redis tcp 0 0 app-server:15174 app-redis-:6375 ESTABLISHED tcp 0 0 app-server:14600 app-redis-:6375 ESTABLISHED tcp 1 0 app-server:2666 app-redis-:6375 CLOSE_WAIT tcp 0 0 app-server:15156 app-redis-:6375 ESTABLISHED tcp 0 0 app-server:15158 app-redis-:6375 ESTABLISHED tcp 0 0 app-server:15170app-redis-:6375 ESTABLISHED

Ideally it should have created 1 connection and queued the rest 4. Right ? Is this a issue from my side?

zhuizhuhaomeng commented 1 year ago

did you call the set_keepalive to put the connection to the pool?

first-mine commented 1 year ago

Yes, set_keepalive is there after connect. local ok, err = red:set_keepalive(1000000, 100)

first-mine commented 1 year ago

Even if set_keepalive wasn't there. It shouldn't have created 5 connection. Right ?

zhuizhuhaomeng commented 1 year ago

Please show your code that can reproduce the problem

first-mine commented 1 year ago

@zhuizhuhaomeng One more observation I found. For red:publish command, new connection is opening every time, I have called the set_keepalive. But for other operations like get, set, lpush, etc the same connection getting reused. Is this a bug or is it supposed to be like this ??