MCPcopy Create free account
hub / github.com/acl-dev/acl / cluster_slaves

Method cluster_slaves

lib_acl_cpp/src/redis/redis_cluster.cpp:637–682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

635//////////////////////////////////////////////////////////////////////////
636
637const std::vector<redis_node*>* redis_cluster::cluster_slaves(const char* node)
638{
639 free_slaves();
640
641 const char* argv[3];
642 size_t lens[3];
643
644 argv[0] = "CLUSTER";
645 lens[0] = sizeof("CLUSTER") - 1;
646
647 argv[1] = "SLAVES";
648 lens[1] = sizeof("SLAVES") - 1;
649
650 argv[2] = node;
651 lens[2] = strlen(node);
652
653 build_request(3, argv, lens);
654
655 std::vector<string> lines;
656 if (get_strings(lines) < 0) {
657 return NULL;
658 }
659
660 std::vector<string>::iterator it = lines.begin();
661 for (; it != lines.end(); ++it) {
662 std::vector<string>& tokens = (*it).split2(" ");
663 if (tokens.size() < 3) {
664 continue;
665 }
666
667 char* node_type = tokens[2].c_str();
668 char* ptr = strchr(node_type, ',');
669 if (ptr != NULL && *(ptr + 1)) {
670 node_type = ptr + 1;
671 }
672 if (strcasecmp(node_type, "slave") != 0) {
673 continue;
674 }
675 redis_node* slave = get_slave(tokens);
676 if (slave != NULL) {
677 slaves_.push_back(slave);
678 }
679 }
680
681 return &slaves_;
682}
683
684redis_node* redis_cluster::get_slave(const std::vector<string>& tokens)
685{

Callers 1

test_slavesFunction · 0.80

Calls 6

beginMethod · 0.80
build_requestFunction · 0.50
endMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45
push_backMethod · 0.45

Tested by 1

test_slavesFunction · 0.64