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

Function ConsumeCommand

src/brpc/policy/redis_protocol.cpp:58–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57
58int ConsumeCommand(RedisConnContext* ctx,
59 const std::vector<butil::StringPiece>& args,
60 bool flush_batched,
61 butil::IOBufAppender* appender) {
62 RedisReply output(&ctx->arena);
63 RedisCommandHandlerResult result = REDIS_CMD_HANDLED;
64 if (ctx->transaction_handler) {
65 result = ctx->transaction_handler->Run(ctx, args, &output, flush_batched);
66 if (result == REDIS_CMD_HANDLED) {
67 ctx->transaction_handler.reset(NULL);
68 } else if (result == REDIS_CMD_BATCHED) {
69 LOG(ERROR) << "BATCHED should not be returned by a transaction handler.";
70 return -1;
71 }
72 } else {
73 RedisCommandHandler* ch = ctx->redis_service->FindCommandHandler(args[0]);
74 if (!ch) {
75 char buf[64];
76 snprintf(buf, sizeof(buf), "ERR unknown command `%s`", args[0].as_string().c_str());
77 output.SetError(buf);
78 } else {
79 result = ch->Run(ctx, args, &output, flush_batched);
80 if (result == REDIS_CMD_CONTINUE) {
81 if (ctx->batched_size != 0) {
82 LOG(ERROR) << "CONTINUE should not be returned in a batched process.";
83 return -1;
84 }
85 ctx->transaction_handler.reset(ch->NewTransactionHandler());
86 } else if (result == REDIS_CMD_BATCHED) {
87 ctx->batched_size++;
88 }
89 }
90 }
91 if (result == REDIS_CMD_HANDLED) {
92 if (ctx->batched_size) {
93 if ((int)output.size() != (ctx->batched_size + 1)) {
94 LOG(ERROR) << "reply array size can't be matched with batched size, "
95 << " expected=" << ctx->batched_size + 1 << " actual=" << output.size();
96 return -1;
97 }
98 for (int i = 0; i < (int)output.size(); ++i) {
99 output[i].SerializeTo(appender);
100 }
101 ctx->batched_size = 0;
102 } else {
103 output.SerializeTo(appender);
104 }
105 } else if (result == REDIS_CMD_CONTINUE) {
106 output.SerializeTo(appender);
107 } else if (result == REDIS_CMD_BATCHED) {
108 // just do nothing and wait handler to return OK.
109 } else {
110 LOG(ERROR) << "unknown status=" << result;
111 return -1;
112 }
113 return 0;
114}
115

Callers 1

ParseRedisMessageFunction · 0.85

Calls 10

snprintfFunction · 0.85
FindCommandHandlerMethod · 0.80
RunMethod · 0.45
resetMethod · 0.45
c_strMethod · 0.45
as_stringMethod · 0.45
SetErrorMethod · 0.45
NewTransactionHandlerMethod · 0.45
sizeMethod · 0.45
SerializeToMethod · 0.45

Tested by

no test coverage detected