modify redis_node class for redis.4.x.x

This commit is contained in:
zsx 2018-01-01 11:05:05 +08:00
parent c2100129d3
commit 344d370715
3 changed files with 12 additions and 28 deletions

View File

@ -40,14 +40,6 @@ public:
*/
redis_node& set_addr(const char* addr);
/**
* redis.4.x.x CLUSTER NODES @xxx
* for redis.4.x.x, the return addr of CLUSTER NODES has @xxx
* @param addr {const char*}
* @return {redis_node&}
*/
redis_node& set_at_addr(const char* addr);
/**
*
* set the current node's type
@ -245,19 +237,19 @@ public:
}
/**
* for redis.4.x.x:
* result of CLUSTER NODES for redis.4.x.x:
* d52ea3cb4cdf7294ac1fb61c696ae6483377bcfc 127.0.0.1:16385@116385 master - 0 1428410625374 73 connected 5461-10922
* @return return @116385 for redis.4.x.x
* @return return 127.0.0.1:16385@116385 for redis.4.x.x
*/
const char* get_at_addr() const
const char* get_addr_info() const
{
return at_addr_.c_str();
return addr_info_.c_str();
}
private:
string id_;
string addr_;
string at_addr_;
string addr_info_;
string type_;
bool myself_;
bool handshaking_;

View File

@ -760,13 +760,7 @@ redis_node* redis_cluster::get_node(string& line)
redis_node* node = NEW redis_node;
node->set_id(tokens[0].c_str());
char *addr = tokens[1].c_str();
char *at = strchr(addr, '@');
if (at)
*at++ = 0;
node->set_addr(addr);
if (at && *at)
node->set_at_addr(at);
node->set_addr(tokens[1].c_str());
node->set_myself(myself);
node->set_connected(strcasecmp(tokens[7].c_str(), "connected") == 0);
node->set_master_id(tokens[3].c_str());

View File

@ -28,14 +28,12 @@ redis_node& redis_node::set_id(const char* id)
redis_node& redis_node::set_addr(const char* addr)
{
addr_ = addr;
return *this;
}
redis_node& redis_node::set_at_addr(const char* addr)
{
if (addr && *addr)
at_addr_ = addr;
addr_info_ = addr;
int pos = addr_info_.find('@');
if (pos <= 0)
addr_ = addr_info_;
else
addr_.copy(addr_info_, pos);
return *this;
}