Commit 0d543fe8 authored by liuminghang's avatar liuminghang

rename commands to args

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