MCPcopy Create free account
hub / github.com/apache/brpc / CallMethodImpl

Method CallMethodImpl

src/brpc/redis_cluster.cpp:291–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291bool RedisClusterChannel::CallMethodImpl(Controller* cntl,
292 const RedisRequest& request,
293 RedisResponse* response) {
294 std::vector<ParsedCommand> commands;
295 if (!ParseRequest(request, &commands, cntl)) {
296 return false;
297 }
298 if (commands.empty()) {
299 cntl->SetFailed(EREQUEST, "request has no redis command");
300 return false;
301 }
302
303 std::vector<butil::IOBuf> replies(commands.size());
304 for (size_t i = 0; i < commands.size(); ++i) {
305 if (!ExecuteCommand(commands[i], &replies[i], cntl)) {
306 return false;
307 }
308 }
309
310 butil::IOBuf merged;
311 for (size_t i = 0; i < replies.size(); ++i) {
312 merged.append(replies[i]);
313 }
314
315 response->Clear();
316 ParseError err = response->ConsumePartialIOBuf(merged, static_cast<int>(commands.size()));
317 if (err != PARSE_OK || !merged.empty()) {
318 cntl->SetFailed(ERESPONSE, "Fail to parse merged redis response");
319 return false;
320 }
321 return true;
322}
323
324bool RedisClusterChannel::ParseRequest(const RedisRequest& request,
325 std::vector<ParsedCommand>* commands,

Callers 1

RunAsyncCallMethod · 0.80

Calls 6

emptyMethod · 0.45
SetFailedMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
ClearMethod · 0.45
ConsumePartialIOBufMethod · 0.45

Tested by

no test coverage detected