connection_idle_time is not working
beibei198918 opened this issue · 4 comments
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:
- OS: ubuntu
- Compiler: gcc 4.8.5
- hiredis version: v1.2.0 , master
- redis-plus-plus version: 1.3.12, master, commit fe6e72f
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);
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
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?
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
Since there's no update, I'll close this issue.
Regards