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

How to create a single redis connection

Open first-mine opened this issue 3 years ago • 5 comments

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?

first-mine avatar Jan 30 '23 10:01 first-mine

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

zhuizhuhaomeng avatar Jan 30 '23 11:01 zhuizhuhaomeng

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

first-mine avatar Jan 30 '23 11:01 first-mine

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

first-mine avatar Jan 30 '23 11:01 first-mine

Please show your code that can reproduce the problem

zhuizhuhaomeng avatar Jan 30 '23 14:01 zhuizhuhaomeng

@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 ??

first-mine avatar Jan 31 '23 09:01 first-mine