boostorg / redis

An async redis client designed for performance and scalability
https://www.boost.org/doc/libs/develop/libs/redis/doc/html/index.html
Boost Software License 1.0
212 stars 38 forks source link

Add ability to check if initial connection to server succeeded #164

Open ferchor2003 opened 8 months ago

ferchor2003 commented 8 months ago

Some application will need to be able to check if initial connection to the server succeeded before sending any traffic to it. in other words, how can an app detect if the connection is up before trying to execute an exec() call?

mzimbres commented 8 months ago

The best way to check if a connection is up is by sending executing a command like PING with exec() command. In principle it is possible to check if the socket is open, but that is not as reliable. My recommendation however is for users to rely on the buil-in health-checker in Boost.Redis instead of trying to detect themselves. The health-checker is capable of establishing a new connection (to the same instance) when necessary.

Also, I recommend you having a look at redis::request::config to adjust the behaviour to your needs, the flag cancel_if_not_connected seems to be what you are looking for.

mzimbres commented 8 months ago

Above I mean the flag boost::redis::request::config::cancel_if_not_connected.

Does that solve your problem? do your need any further help?