Commit 0d543fe8 authored by liuminghang's avatar liuminghang

rename commands to args

parent a8f27723
...@@ -76,13 +76,13 @@ public: ...@@ -76,13 +76,13 @@ public:
}; };
int ConsumeCommand(RedisConnContext* ctx, int ConsumeCommand(RedisConnContext* ctx,
const std::vector<butil::StringPiece>& commands, const std::vector<butil::StringPiece>& args,
bool flush_batched, bool flush_batched,
butil::IOBufAppender* appender) { butil::IOBufAppender* appender) {
RedisReply output(&ctx->arena); RedisReply output(&ctx->arena);
RedisCommandHandlerResult result = REDIS_CMD_HANDLED; RedisCommandHandlerResult result = REDIS_CMD_HANDLED;
if (ctx->transaction_handler) { if (ctx->transaction_handler) {
result = ctx->transaction_handler->Run(commands, &output, flush_batched); result = ctx->transaction_handler->Run(args, &output, flush_batched);
if (result == REDIS_CMD_HANDLED) { if (result == REDIS_CMD_HANDLED) {
ctx->transaction_handler.reset(NULL); ctx->transaction_handler.reset(NULL);
} else if (result == REDIS_CMD_BATCHED) { } else if (result == REDIS_CMD_BATCHED) {
...@@ -90,13 +90,13 @@ int ConsumeCommand(RedisConnContext* ctx, ...@@ -90,13 +90,13 @@ int ConsumeCommand(RedisConnContext* ctx,
return -1; return -1;
} }
} else { } else {
RedisCommandHandler* ch = ctx->redis_service->FindCommandHandler(commands[0]); RedisCommandHandler* ch = ctx->redis_service->FindCommandHandler(args[0]);
if (!ch) { if (!ch) {
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "ERR unknown command `%s`", commands[0].as_string().c_str()); snprintf(buf, sizeof(buf), "ERR unknown command `%s`", args[0].as_string().c_str());
output.SetError(buf); output.SetError(buf);
} else { } else {
result = ch->Run(commands, &output, flush_batched); result = ch->Run(args, &output, flush_batched);
if (result == REDIS_CMD_CONTINUE) { if (result == REDIS_CMD_CONTINUE) {
if (ctx->batched_size != 0) { if (ctx->batched_size != 0) {
LOG(ERROR) << "CONTINUE should not be returned in a batched process."; LOG(ERROR) << "CONTINUE should not be returned in a batched process.";
...@@ -159,26 +159,26 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket, ...@@ -159,26 +159,26 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
ctx = new RedisConnContext(rs); ctx = new RedisConnContext(rs);
socket->reset_parsing_context(ctx); socket->reset_parsing_context(ctx);
} }
std::vector<butil::StringPiece> current_commands; std::vector<butil::StringPiece> current_args;
butil::IOBufAppender appender; butil::IOBufAppender appender;
ParseError err = PARSE_OK; ParseError err = PARSE_OK;
err = ctx->parser.Consume(*source, &current_commands, &ctx->arena); err = ctx->parser.Consume(*source, &current_args, &ctx->arena);
if (err != PARSE_OK) { if (err != PARSE_OK) {
return MakeParseError(err); return MakeParseError(err);
} }
while (true) { while (true) {
std::vector<butil::StringPiece> next_commands; std::vector<butil::StringPiece> next_args;
err = ctx->parser.Consume(*source, &next_commands, &ctx->arena); err = ctx->parser.Consume(*source, &next_args, &ctx->arena);
if (err != PARSE_OK) { if (err != PARSE_OK) {
break; break;
} }
if (ConsumeCommand(ctx, current_commands, false, &appender) != 0) { if (ConsumeCommand(ctx, current_args, false, &appender) != 0) {
return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG); return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
} }
current_commands.swap(next_commands); current_args.swap(next_args);
} }
if (ConsumeCommand(ctx, current_commands, if (ConsumeCommand(ctx, current_args,
true /*must be the last message*/, &appender) != 0) { true /*must be the last message*/, &appender) != 0) {
return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG); return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
} }
......
...@@ -362,7 +362,7 @@ RedisCommandParser::RedisCommandParser() ...@@ -362,7 +362,7 @@ RedisCommandParser::RedisCommandParser()
, _index(0) {} , _index(0) {}
ParseError RedisCommandParser::Consume(butil::IOBuf& buf, ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
std::vector<butil::StringPiece>* commands, std::vector<butil::StringPiece>* args,
butil::Arena* arena) { butil::Arena* arena) {
const char* pfc = (const char*)buf.fetch1(); const char* pfc = (const char*)buf.fetch1();
if (pfc == NULL) { if (pfc == NULL) {
...@@ -398,8 +398,8 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf, ...@@ -398,8 +398,8 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
_parsing_array = true; _parsing_array = true;
_length = value; _length = value;
_index = 0; _index = 0;
_commands.resize(value); _args.resize(value);
return Consume(buf, commands, arena); return Consume(buf, args, arena);
} }
CHECK(_index < _length) << "a complete command has been parsed. " CHECK(_index < _length) << "a complete command has been parsed. "
"impl of RedisCommandParser::Parse is buggy"; "impl of RedisCommandParser::Parse is buggy";
...@@ -420,7 +420,7 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf, ...@@ -420,7 +420,7 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
char* d = (char*)arena->allocate((len/8 + 1) * 8); char* d = (char*)arena->allocate((len/8 + 1) * 8);
buf.cutn(d, len); buf.cutn(d, len);
d[len] = '\0'; d[len] = '\0';
_commands[_index] = butil::StringPiece(d, len); _args[_index] = butil::StringPiece(d, len);
if (_index == 0) { if (_index == 0) {
// convert it to lowercase when it is command name // convert it to lowercase when it is command name
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
...@@ -434,9 +434,9 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf, ...@@ -434,9 +434,9 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
return PARSE_ERROR_ABSOLUTELY_WRONG; return PARSE_ERROR_ABSOLUTELY_WRONG;
} }
if (++_index < _length) { if (++_index < _length) {
return Consume(buf, commands, arena); return Consume(buf, args, arena);
} }
commands->swap(_commands); args->swap(_args);
Reset(); Reset();
return PARSE_OK; return PARSE_OK;
} }
...@@ -445,7 +445,7 @@ void RedisCommandParser::Reset() { ...@@ -445,7 +445,7 @@ void RedisCommandParser::Reset() {
_parsing_array = false; _parsing_array = false;
_length = 0; _length = 0;
_index = 0; _index = 0;
_commands.clear(); _args.clear();
} }
} // namespace brpc } // namespace brpc
...@@ -48,9 +48,9 @@ public: ...@@ -48,9 +48,9 @@ public:
RedisCommandParser(); RedisCommandParser();
// Parse raw message from `buf'. Return PARSE_OK and set the parsed command // Parse raw message from `buf'. Return PARSE_OK and set the parsed command
// to `commands' and length to `len' if successful. Memory of commands are // to `args' and length to `len' if successful. Memory of args are allocated
// allocated in `arena'. // in `arena'.
ParseError Consume(butil::IOBuf& buf, std::vector<butil::StringPiece>* commands, ParseError Consume(butil::IOBuf& buf, std::vector<butil::StringPiece>* args,
butil::Arena* arena); butil::Arena* arena);
private: private:
...@@ -60,7 +60,7 @@ private: ...@@ -60,7 +60,7 @@ private:
bool _parsing_array; // if the parser has met array indicator '*' bool _parsing_array; // if the parser has met array indicator '*'
int _length; // array length int _length; // array length
int _index; // current parsing array index int _index; // current parsing array index
std::vector<butil::StringPiece> _commands; // parsed command string std::vector<butil::StringPiece> _args; // parsed command string
}; };
} // namespace brpc } // namespace brpc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment