| 643 | } |
| 644 | |
| 645 | bool RedisClusterChannel::SendToEndpoint(const std::string& endpoint, |
| 646 | const std::vector<std::string>& args, |
| 647 | bool asking, |
| 648 | SingleCommandResult* result, |
| 649 | RedirectInfo* redirect, |
| 650 | Controller* cntl) { |
| 651 | result->ok = false; |
| 652 | redirect->valid = false; |
| 653 | redirect->asking = false; |
| 654 | redirect->slot = -1; |
| 655 | redirect->endpoint.clear(); |
| 656 | |
| 657 | Channel* channel = GetOrCreateChannel(endpoint); |
| 658 | if (channel == NULL) { |
| 659 | cntl->SetFailed(EHOSTDOWN, "Fail to get channel for %s", endpoint.c_str()); |
| 660 | return false; |
| 661 | } |
| 662 | |
| 663 | RedisRequest request; |
| 664 | if (asking) { |
| 665 | if (!request.AddCommand("asking")) { |
| 666 | cntl->SetFailed(EREQUEST, "Fail to build ASKING command"); |
| 667 | return false; |
| 668 | } |
| 669 | std::vector<butil::StringPiece> components; |
| 670 | components.reserve(args.size()); |
| 671 | for (size_t i = 0; i < args.size(); ++i) { |
| 672 | components.push_back(args[i]); |
| 673 | } |
| 674 | if (!request.AddCommandByComponents(&components[0], components.size())) { |
| 675 | cntl->SetFailed(EREQUEST, "Fail to build redis command"); |
| 676 | return false; |
| 677 | } |
| 678 | } else { |
| 679 | if (!BuildRedisRequest(args, &request)) { |
| 680 | cntl->SetFailed(EREQUEST, "Fail to build redis command"); |
| 681 | return false; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | RedisResponse response; |
| 686 | Controller sub_cntl; |
| 687 | if (cntl->timeout_ms() > 0) { |
| 688 | sub_cntl.set_timeout_ms(cntl->timeout_ms()); |
| 689 | } |
| 690 | channel->CallMethod(NULL, &sub_cntl, &request, &response, NULL); |
| 691 | if (sub_cntl.Failed()) { |
| 692 | cntl->SetFailed(sub_cntl.ErrorCode(), |
| 693 | "Redis cluster sub-request to %s failed: %s", |
| 694 | endpoint.c_str(), |
| 695 | sub_cntl.ErrorText().c_str()); |
| 696 | return false; |
| 697 | } |
| 698 | |
| 699 | const int expected = asking ? 2 : 1; |
| 700 | if (response.reply_size() != expected) { |
| 701 | cntl->SetFailed(ERESPONSE, |
| 702 | "Unexpected redis response size=%d expected=%d", |
nothing calls this directly
no test coverage detected