service_guard: there're bugs in service_node.cpp for using redis_zset::save.

This commit is contained in:
zsx 2018-01-26 10:44:52 +08:00
parent 2242fd58aa
commit ebd2c013f0
2 changed files with 13 additions and 7 deletions

View File

@ -64,19 +64,21 @@ bool guard_action::on_service_list(acl::json& json)
return false;
}
bool ret = true;
service_node node(var_redis);
if (node.save(ip_, res) == false) {
logger_error("save error, ip=%s", ip_.c_str());
return false;
ret = false;
}
service_app app(var_redis);
if (app.save(ip_, res) == false) {
logger_error("save app info error, ip=%s", ip_.c_str());
return false;
ret = false;
}
return true;
return ret;
}
bool guard_action::on_service_dead(acl::json& json)

View File

@ -28,11 +28,14 @@ bool service_node::save(const char* ip, const service_list_res_t& res)
bool ret = true;
acl::redis cmd(&redis_);
if (cmd.zadd(ip, members) < 0) {
logger_error("zadd error=%s, ip=%s", cmd.result_error(), ip);
if (cmd.zadd(ip, members) == -1) {
logger_error("zadd error=%s, ip=%s, members=%d",
cmd.result_error(), ip, (int) members.size());
ret = false;
}
cmd.clear();
acl::string key;
members.clear();
for (std::vector<service_info_t>::const_iterator cit = res.data.begin();
@ -42,8 +45,9 @@ bool service_node::save(const char* ip, const service_list_res_t& res)
members[key] = now;
}
if (cmd.zadd(SERVICES, members) == false) {
logger_error("zadd error=%s, ip=%s", cmd.result_error(), ip);
if (cmd.zadd(SERVICES, members) == -1) {
logger_error("zadd error=%s, ip=%s, members=%d",
cmd.result_error(), ip, (int) members.size());
ret = false;
}