Redis_Client is_connected=true, even when network redis device is unplugged
Adityav2410 opened this issue · 0 comments
Adityav2410 commented
Describe the bug
I connect to a remote redis-server. Later if i disconnect the remote device from network, redis_client still says is_connected=true
OS: ubuntu18,04
Aarch 64
cpp_redis: 4.4.0-beta.1 and master
int main() {
cpp_redis::client redis_client;
auto connCallbackFn = [&redis_client](const std::string& host,
std::size_t port,
cpp_redis::connect_state status) {
std::string name = "Redis";
LOG(ERROR) << "Redis Connector callback made. Status: ";
if (status == cpp_redis::connect_state::dropped)
LOG(INFO) << name << " Connection: Dropped";
else if (status == cpp_redis::connect_state::start)
LOG(INFO) << name << " Connection: Start";
else if (status == cpp_redis::connect_state::sleeping)
LOG(INFO) << name << " Connection: Sleeping";
else if (status == cpp_redis::connect_state::ok)
LOG(INFO) << name << " Connection: OK";
else if (status == cpp_redis::connect_state::failed)
LOG(INFO) << name << " Connection: Failed";
else if (status == cpp_redis::connect_state::lookup_failed)
LOG(INFO) << name << " Connection: LookupFailed";
else if (status == cpp_redis::connect_state::stopped)
LOG(INFO) << name << " Connection: Stopped";
};
redis_client.connect("192.168.0.17", 6379, connCallbackFn, 2000);
while (true) {
if (redis_client.is_connected())
LOG(INFO) << "Connected...";
else
LOG(INFO) << "Not connected...";
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}
Logs:
E0525 21:09:37.313364 2975 test_redis.cpp:14] Redis Connector callback made. Status:
I0525 21:09:37.313477 2975 test_redis.cpp:18] Redis Connection: Start
E0525 21:09:37.314191 2975 test_redis.cpp:14] Redis Connector callback made. Status:
I0525 21:09:37.314225 2975 test_redis.cpp:22] Redis Connection: OK
I0525 21:09:37.314242 2975 test_redis.cpp:33] Connected...
I0525 21:09:39.314694 2975 test_redis.cpp:33] Connected...
<UNPLUG REMOTE DEVICE FROM NETWORK>
I0525 21:09:41.315685 2975 test_redis.cpp:33] Connected...
Once i unplug my remote device with redis-server from network, I expect another callback, and the redis_client.is_connected() should return false.
Am I understanding it wrong. How to get informed if redis_client connection is lost?