ledgetech / lua-resty-redis-connector

Connection utilities for lua-resty-redis
234 stars 71 forks source link

Sentinels & Connection Pooling #46

Closed synologic closed 2 years ago

synologic commented 2 years ago

This seems to go around for some time, but nothing i found suggests a reliable fix.

I am connecting via sentinels

local rc = require("resty.redis.connector").new({ connect_timeout = 1000, read_timeout = 5000, master_name = "redis-cluster", sentinels = redisSentinels, role = "master" })

local redis, err = rc:connect()

Whenever i do

local ok, err = rc:set_keepalive(redis)

I am no longer able to send commands due to

attempt to send data on a closed socket

This is used in a location access_by_lua_file

redis:get_reused_times() returns the number of reuses correctly, but i cannot figure out why i get the closed socket issue

I'm using v0..11 of the lib and openresty 1.19.9.1

Any suggestions ?

pintsized commented 2 years ago

https://github.com/openresty/lua-nginx-module/#tcpsocksetkeepalive

"This method also makes the current cosocket object enter the "closed" state, so there is no need to manually call the close method on it afterwards."

In other words, call set_keepalive where you would normally call close, and it will be available in the pool next time you call connect.

synologic commented 2 years ago

What a stupid mistake on my part ...

Thanks for the guidance, it works fine when done the proper way ;-)