| 635 | ////////////////////////////////////////////////////////////////////////// |
| 636 | |
| 637 | const 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 | |
| 684 | redis_node* redis_cluster::get_slave(const std::vector<string>& tokens) |
| 685 | { |