Commit e804f191 authored by zhujiashun's avatar zhujiashun

redis_server_protocol: change flush_back to flush_batched

parent 22ad6a8d
......@@ -79,12 +79,12 @@ public:
int ConsumeCommand(RedisConnContext* ctx,
const std::vector<const char*>& commands,
bool flush_back,
bool flush_batched,
butil::IOBufAppender* appender) {
RedisReply output(&ctx->arena);
RedisCommandHandler::Result result = RedisCommandHandler::OK;
if (ctx->transaction_handler) {
result = ctx->transaction_handler->Run(commands, &output, flush_back);
result = ctx->transaction_handler->Run(commands, &output, flush_batched);
if (result == RedisCommandHandler::OK) {
ctx->transaction_handler.reset(NULL);
} else if (result == RedisCommandHandler::BATCHED) {
......@@ -98,7 +98,7 @@ int ConsumeCommand(RedisConnContext* ctx,
snprintf(buf, sizeof(buf), "ERR unknown command `%s`", commands[0]);
output.SetError(buf);
} else {
result = ch->Run(commands, &output, flush_back);
result = ch->Run(commands, &output, flush_batched);
if (result == RedisCommandHandler::CONTINUE) {
if (ctx->batched_size != 0) {
LOG(ERROR) << "CONTINUE should not be returned in a batched process.";
......
......@@ -248,9 +248,9 @@ public:
// corresponds to args[0]=="set", args[1]=="somekey" and args[2]=="somevalue".
// `output', which should be filled by user, is the content that sent to client side.
// Read brpc/src/redis_reply.h for more usage.
// `flush_back' indicates whether the user should flush back all the results of
// `flush_batched' indicates whether the user should flush all the results of
// batched commands. If user want to do some batch processing, user should buffer
// the commands and return RedisCommandHandler::BATCHED. Once `flush_back' is true,
// the commands and return RedisCommandHandler::BATCHED. Once `flush_batched' is true,
// run all the commands, set `output' to be an array in which every element is the
// result of batched commands and return RedisCommandHandler::OK.
//
......@@ -261,7 +261,7 @@ public:
// it returns RedisCommandHandler::OK. Read the comment below.
virtual RedisCommandHandler::Result Run(const std::vector<const char*>& args,
brpc::RedisReply* output,
bool flush_back) = 0;
bool flush_batched) = 0;
// The Run() returns CONTINUE for "multi", which makes brpc call this method to
// create a transaction_handler to process following commands until transaction_handler
......
......@@ -50,30 +50,30 @@ bool RedisReply::SerializeTo(butil::IOBufAppender* appender) {
} else {
appender->append(_data.long_str, _length);
}
appender->append("\r\n");
appender->append("\r\n", 2);
break;
case REDIS_REPLY_INTEGER:
appender->push_back(':');
appender->append_decimal(_data.integer);
appender->append("\r\n");
appender->append("\r\n", 2);
break;
case REDIS_REPLY_STRING:
appender->push_back('$');
appender->append_decimal(_length);
appender->append("\r\n");
appender->append("\r\n", 2);
if (_length != npos) {
if (_length < (int)sizeof(_data.short_str)) {
appender->append(_data.short_str, _length);
} else {
appender->append(_data.long_str, _length);
}
appender->append("\r\n");
appender->append("\r\n", 2);
}
break;
case REDIS_REPLY_ARRAY:
appender->push_back('*');
appender->append_decimal(_length);
appender->append("\r\n");
appender->append("\r\n", 2);
if (_length != npos) {
for (int i = 0; i < _length; ++i) {
if (!_data.array.replies[i].SerializeTo(appender)) {
......@@ -83,8 +83,8 @@ bool RedisReply::SerializeTo(butil::IOBufAppender* appender) {
}
break;
case REDIS_REPLY_NIL:
appender->append("$-1\r\n");
break;
LOG(ERROR) << "Do you forget to call SetXXX()?";
return false;
default:
CHECK(false) << "unknown redis type=" << _type;
return false;
......
......@@ -798,8 +798,8 @@ public:
: _batch_count(0) {}
brpc::RedisCommandHandler::Result OnBatched(const std::vector<const char*> args,
brpc::RedisReply* output, bool flush_back) {
if (_batched_command.empty() && flush_back) {
brpc::RedisReply* output, bool flush_batched) {
if (_batched_command.empty() && flush_batched) {
if (strcmp(args[0], "set") == 0) {
DoSet(args[1], args[2], output);
} else if (strcmp(args[0], "get") == 0) {
......@@ -812,7 +812,7 @@ public:
comm.push_back(args[i]);
}
_batched_command.push_back(comm);
if (flush_back) {
if (flush_batched) {
output->SetArray(_batched_command.size());
for (int i = 0; i < (int)_batched_command.size(); ++i) {
if (_batched_command[i][0] == "set") {
......@@ -856,13 +856,13 @@ public:
brpc::RedisCommandHandler::Result Run(const std::vector<const char*>& args,
brpc::RedisReply* output,
bool flush_back) {
bool flush_batched) {
if (args.size() < 3) {
output->SetError("ERR wrong number of arguments for 'set' command");
return brpc::RedisCommandHandler::OK;
}
if (_batch_process) {
return rs->OnBatched(args, output, flush_back);
return rs->OnBatched(args, output, flush_batched);
} else {
DoSet(args[1], args[2], output);
return brpc::RedisCommandHandler::OK;
......@@ -887,13 +887,13 @@ public:
brpc::RedisCommandHandler::Result Run(const std::vector<const char*>& args,
brpc::RedisReply* output,
bool flush_back) {
bool flush_batched) {
if (args.size() < 2) {
output->SetError("ERR wrong number of arguments for 'get' command");
return brpc::RedisCommandHandler::OK;
}
if (_batch_process) {
return rs->OnBatched(args, output, flush_back);
return rs->OnBatched(args, output, flush_batched);
} else {
DoGet(args[1], output);
return brpc::RedisCommandHandler::OK;
......@@ -920,7 +920,7 @@ public:
brpc::RedisCommandHandler::Result Run(const std::vector<const char*>& args,
brpc::RedisReply* output,
bool flush_back) {
bool flush_batched) {
if (args.size() < 2) {
output->SetError("ERR wrong number of arguments for 'incr' command");
return brpc::RedisCommandHandler::OK;
......@@ -1034,7 +1034,7 @@ public:
brpc::RedisCommandHandler::Result Run(const std::vector<const char*>& args,
brpc::RedisReply* output,
bool flush_back) {
bool flush_batched) {
output->SetStatus("OK");
return brpc::RedisCommandHandler::CONTINUE;
}
......@@ -1047,7 +1047,7 @@ public:
public:
brpc::RedisCommandHandler::Result Run(const std::vector<const char*>& args,
brpc::RedisReply* output,
bool flush_back) {
bool flush_batched) {
if (strcmp(args[0], "multi") == 0) {
output->SetError("ERR duplicate multi");
return brpc::RedisCommandHandler::CONTINUE;
......
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