mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-16 14:18:24 +00:00
fix XREAD commands for redis message queue
This commit is contained in:
@ -937,15 +937,16 @@ void PostgreSQL::_membersWatcher_Postgres() {
|
|||||||
void PostgreSQL::_membersWatcher_Redis() {
|
void PostgreSQL::_membersWatcher_Redis() {
|
||||||
char buf[11] = {0};
|
char buf[11] = {0};
|
||||||
std::string key = "member-stream:{" + std::string(_myAddress.toString(buf)) + "}";
|
std::string key = "member-stream:{" + std::string(_myAddress.toString(buf)) + "}";
|
||||||
|
std::string lastID = "0";
|
||||||
fprintf(stderr, "Listening to member stream: %s\n", key.c_str());
|
fprintf(stderr, "Listening to member stream: %s\n", key.c_str());
|
||||||
while (_run == 1) {
|
while (_run == 1) {
|
||||||
try {
|
try {
|
||||||
json tmp;
|
json tmp;
|
||||||
std::unordered_map<std::string, ItemStream> result;
|
std::unordered_map<std::string, ItemStream> result;
|
||||||
if (_rc->clusterMode) {
|
if (_rc->clusterMode) {
|
||||||
_cluster->xread(key, "$", std::chrono::seconds(1), 0, std::inserter(result, result.end()));
|
_cluster->xread(key, lastID, std::chrono::seconds(1), 10, std::inserter(result, result.end()));
|
||||||
} else {
|
} else {
|
||||||
_redis->xread(key, "$", std::chrono::seconds(1), 0, std::inserter(result, result.end()));
|
_redis->xread(key, lastID, std::chrono::seconds(1), 10, std::inserter(result, result.end()));
|
||||||
}
|
}
|
||||||
if (!result.empty()) {
|
if (!result.empty()) {
|
||||||
for (auto element : result) {
|
for (auto element : result) {
|
||||||
@ -982,6 +983,7 @@ void PostgreSQL::_membersWatcher_Redis() {
|
|||||||
} else {
|
} else {
|
||||||
_redis->xdel(key, id);
|
_redis->xdel(key, id);
|
||||||
}
|
}
|
||||||
|
lastID = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1024,15 +1026,15 @@ void PostgreSQL::_networksWatcher_Postgres() {
|
|||||||
void PostgreSQL::_networksWatcher_Redis() {
|
void PostgreSQL::_networksWatcher_Redis() {
|
||||||
char buf[11] = {0};
|
char buf[11] = {0};
|
||||||
std::string key = "network-stream:{" + std::string(_myAddress.toString(buf)) + "}";
|
std::string key = "network-stream:{" + std::string(_myAddress.toString(buf)) + "}";
|
||||||
|
std::string lastID = "0";
|
||||||
while (_run == 1) {
|
while (_run == 1) {
|
||||||
try {
|
try {
|
||||||
json tmp;
|
json tmp;
|
||||||
std::unordered_map<std::string, ItemStream> result;
|
std::unordered_map<std::string, ItemStream> result;
|
||||||
if (_rc->clusterMode) {
|
if (_rc->clusterMode) {
|
||||||
_cluster->xread(key, "$", std::chrono::seconds(1), 0, std::inserter(result, result.end()));
|
_cluster->xread(key, lastID, std::chrono::seconds(1), 0, std::inserter(result, result.end()));
|
||||||
} else {
|
} else {
|
||||||
_redis->xread(key, "$", std::chrono::seconds(1), 0, std::inserter(result, result.end()));
|
_redis->xread(key, lastID, std::chrono::seconds(1), 0, std::inserter(result, result.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.empty()) {
|
if (!result.empty()) {
|
||||||
@ -1070,6 +1072,7 @@ void PostgreSQL::_networksWatcher_Redis() {
|
|||||||
} else {
|
} else {
|
||||||
_redis->xdel(key, id);
|
_redis->xdel(key, id);
|
||||||
}
|
}
|
||||||
|
lastID = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user