sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.6k stars 347 forks source link

connection_idle_time is not working #566

Closed beibei198918 closed 3 months ago

beibei198918 commented 4 months ago

Describe the problem I used connection pool: pool_options.connection_idle_time = std::chrono::milliseconds(1000*10); After executing the command, the connection was idle for 2422 seconds, but netstat still checked and the connection was not disconnected. What is the problem?

Environment:

Additional context Here is the relevant code: sw::redis::ConnectionOptions connection_options; connection_options.host = "x.x.x.x"; connection_options.port = 6379; connection_options.password = "aaaa"; connection_options.socket_timeout = std::chrono::milliseconds(200);

sw::redis::ConnectionPoolOptions pool_options;
pool_options.size = 10;
pool_options.wait_timeout = std::chrono::milliseconds(100);
pool_options.connection_idle_time = std::chrono::milliseconds(1000*10);

sw::redis::Redis redis(connection_options,pool_options);
sewenew commented 3 months ago

redis-plus-plus does not have a background thread to close these idle connections. Instead, it reconnects the connection when you use it to send a command.

So, the next time, you send some command with an idle connection, redis-plus-plus will close it, and create a new connection to send your command.

Regards

beibei198918 commented 3 months ago

redis-plus-plus does not have a background thread to close these idle connections. Instead, it reconnects the connection when you use it to send a command.

So, the next time, you send some command with an idle connection, redis-plus-plus will close it, and create a new connection to send your command.

Regards

Is there a way to reduce idle connections?

sewenew commented 3 months ago

You can config Redis server to make it close idle connections. Check the timeout config in redis.conf:

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0
sewenew commented 3 months ago

Since there's no update, I'll close this issue.

Regards