Commit e804f191 authored by zhujiashun's avatar zhujiashun

redis_server_protocol: change flush_back to flush_batched

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