This repository was archived by the owner on Apr 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 561
This repository was archived by the owner on Apr 6, 2019. It is now read-only.
No reply when reconnection completed. #70
Copy link
Copy link
Closed
Description
I tried a simple reconnection in callback of client connect:
void RedisSender::connect() {
try {
this->client->connect(this->host, this->port, [this](cpp_redis::redis_client&) {
LOG(WARNING) << "Redis disconnected, reconnecting..." << endl;
this_thread::sleep_for(chrono::seconds(1));
if((++ this->retries) < RECONNECT_RETRIES)
this->connect();
});
if(this->auth.length() > 0)
this->client->auth(this->auth, [](cpp_redis::reply& reply) {
if(string("OK").compare(reply.as_string()) != 0)
LOG(FATAL) << "Redis client authenticated failed.";
});
this->client->select(this->db, [](cpp_redis::reply& reply) {
if(string("OK").compare(reply.as_string()) != 0)
LOG(FATAL) << "Redis client select db failed.";
});
LOG(INFO) << "Redis client connected to " << this->host << ":" << this->port << "/" << this->db;
this->client->commit();
}
catch(exception &e) {
LOG(ERROR) << "Redis client connected failed with " << e.what();
this_thread::sleep_for(chrono::seconds(1));
if((++ this->retries) < RECONNECT_RETRIES)
this->connect();
}
}
// and a loop for test:
void RedisSender::test(string key, string value) {
try{
this->client->set(key, value);
this->client->get(key, [](cpp_redis::reply& reply) {
LOG(INFO) << "get hello: " << reply;
});
LOG(WARNING) << "test " << value;
this->client->commit();
}
catch(exception &e) {
this_thread::sleep_for(chrono::seconds(1));
LOG(WARNING) << "failed ";
}
}Then I restat the redis-server, after the reconnection successfully completed, no reply such as "get hello: xx" outputs, but "set" command just work fine!
so how should I fix this issue.