Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis_Client is_connected=true, even when network redis device is unplugged #65

Open
Adityav2410 opened this issue May 25, 2020 · 0 comments

Comments

@Adityav2410
Copy link

Adityav2410 commented May 25, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant