add online controller list in Redis

This commit is contained in:
Grant Limberg 2020-05-22 14:16:04 -07:00
parent beedee4401
commit 39da360725
No known key found for this signature in database
GPG Key ID: 2BA62CCABBB4095A

View File

@ -686,12 +686,13 @@ void PostgreSQL::heartbeat()
PQfinish(conn); PQfinish(conn);
exit(6); exit(6);
} }
int64_t ts = OSUtils::now();
if (conn) { if (conn) {
std::string major = std::to_string(ZEROTIER_ONE_VERSION_MAJOR); std::string major = std::to_string(ZEROTIER_ONE_VERSION_MAJOR);
std::string minor = std::to_string(ZEROTIER_ONE_VERSION_MINOR); std::string minor = std::to_string(ZEROTIER_ONE_VERSION_MINOR);
std::string rev = std::to_string(ZEROTIER_ONE_VERSION_REVISION); std::string rev = std::to_string(ZEROTIER_ONE_VERSION_REVISION);
std::string build = std::to_string(ZEROTIER_ONE_VERSION_BUILD); std::string build = std::to_string(ZEROTIER_ONE_VERSION_BUILD);
std::string now = std::to_string(OSUtils::now()); std::string now = std::to_string(ts);
std::string host_port = std::to_string(_listenPort); std::string host_port = std::to_string(_listenPort);
std::string use_redis = (_rc != NULL) ? "true" : "false"; std::string use_redis = (_rc != NULL) ? "true" : "false";
const char *values[10] = { const char *values[10] = {
@ -726,6 +727,13 @@ void PostgreSQL::heartbeat()
} }
PQclear(res); PQclear(res);
} }
if (_rc != NULL) {
if (_rc->clusterMode) {
_cluster->zadd("controllers", controllerId, ts);
} else {
_redis->zadd("controllers", controllerId, ts);
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
} }