| 322 | } |
| 323 | |
| 324 | bool RedisClusterChannel::ParseRequest(const RedisRequest& request, |
| 325 | std::vector<ParsedCommand>* commands, |
| 326 | Controller* cntl) const { |
| 327 | commands->clear(); |
| 328 | |
| 329 | butil::IOBuf serialized; |
| 330 | if (!request.SerializeTo(&serialized)) { |
| 331 | cntl->SetFailed(EREQUEST, "Fail to serialize redis request"); |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | RedisCommandParser parser; |
| 336 | butil::Arena arena; |
| 337 | |
| 338 | while (!serialized.empty()) { |
| 339 | std::vector<butil::StringPiece> args; |
| 340 | ParseError err = parser.Consume(serialized, &args, &arena); |
| 341 | if (err != PARSE_OK) { |
| 342 | cntl->SetFailed(EREQUEST, "Fail to parse redis request (err=%d)", err); |
| 343 | return false; |
| 344 | } |
| 345 | ParsedCommand cmd; |
| 346 | cmd.args.reserve(args.size()); |
| 347 | for (size_t i = 0; i < args.size(); ++i) { |
| 348 | cmd.args.push_back(args[i].as_string()); |
| 349 | } |
| 350 | commands->push_back(cmd); |
| 351 | } |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | bool RedisClusterChannel::ExecuteCommand(const ParsedCommand& cmd, |
| 356 | butil::IOBuf* encoded_reply, |