Commit 1b342f75 authored by zhujiashun's avatar zhujiashun

redis_server_protocol: rename RedisMessage back to RedisReply

parent 64d0bcea
...@@ -58,7 +58,7 @@ struct InputResponse : public InputMessageBase { ...@@ -58,7 +58,7 @@ struct InputResponse : public InputMessageBase {
} }
}; };
const char** ParseArgs(const RedisMessage& message) { const char** ParseArgs(const RedisReply& message) {
const char** args = (const char**) const char** args = (const char**)
malloc(sizeof(const char*) * (message.size() + 1 /* NULL */)); malloc(sizeof(const char*) * (message.size() + 1 /* NULL */));
for (size_t i = 0; i < message.size(); ++i) { for (size_t i = 0; i < message.size(); ++i) {
...@@ -122,8 +122,8 @@ private: ...@@ -122,8 +122,8 @@ private:
butil::atomic<bool> _ready; butil::atomic<bool> _ready;
public: public:
RedisMessage input_message; RedisReply input_message;
RedisMessage output_message; RedisReply output_message;
RedisConnContext* ctx; RedisConnContext* ctx;
butil::IOBuf sendbuf; butil::IOBuf sendbuf;
butil::Arena arena; butil::Arena arena;
...@@ -133,7 +133,7 @@ int ConsumeTask(RedisConnContext* ctx, ConsumeTaskDone* done) { ...@@ -133,7 +133,7 @@ int ConsumeTask(RedisConnContext* ctx, ConsumeTaskDone* done) {
ClosureGuard done_guard(done); ClosureGuard done_guard(done);
done->ctx = ctx; done->ctx = ctx;
ctx->Push(done); ctx->Push(done);
RedisMessage& output = done->output_message; RedisReply& output = done->output_message;
const char** args = ParseArgs(done->input_message); const char** args = ParseArgs(done->input_message);
if (!args) { if (!args) {
...@@ -339,7 +339,7 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket, ...@@ -339,7 +339,7 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
if (pi.with_auth) { if (pi.with_auth) {
if (msg->response.reply_size() != 1 || if (msg->response.reply_size() != 1 ||
!(msg->response.reply(0).type() == brpc::REDIS_MESSAGE_STATUS && !(msg->response.reply(0).type() == brpc::REDIS_REPLY_STATUS &&
msg->response.reply(0).data().compare("OK") == 0)) { msg->response.reply(0).data().compare("OK") == 0)) {
LOG(ERROR) << "Redis Auth failed: " << msg->response; LOG(ERROR) << "Redis Auth failed: " << msg->response;
return MakeParseError(PARSE_ERROR_NO_RESOURCE, return MakeParseError(PARSE_ERROR_NO_RESOURCE,
......
...@@ -322,10 +322,10 @@ void RedisResponse::MergeFrom(const RedisResponse& from) { ...@@ -322,10 +322,10 @@ void RedisResponse::MergeFrom(const RedisResponse& from) {
_nreply = new_nreply; _nreply = new_nreply;
return; return;
} }
RedisMessage* new_others = RedisReply* new_others =
(RedisMessage*)_arena.allocate(sizeof(RedisMessage) * (new_nreply - 1)); (RedisReply*)_arena.allocate(sizeof(RedisReply) * (new_nreply - 1));
for (int i = 0; i < new_nreply - 1; ++i) { for (int i = 0; i < new_nreply - 1; ++i) {
new (new_others + i) RedisMessage(NULL); new (new_others + i) RedisReply(NULL);
} }
int new_other_index = 0; int new_other_index = 0;
for (int i = 1; i < _nreply; ++i) { for (int i = 1; i < _nreply; ++i) {
...@@ -394,14 +394,14 @@ ParseError RedisResponse::ConsumePartialIOBuf(butil::IOBuf& buf, int reply_count ...@@ -394,14 +394,14 @@ ParseError RedisResponse::ConsumePartialIOBuf(butil::IOBuf& buf, int reply_count
} }
if (reply_count > 1) { if (reply_count > 1) {
if (_other_replies == NULL) { if (_other_replies == NULL) {
_other_replies = (RedisMessage*)_arena.allocate( _other_replies = (RedisReply*)_arena.allocate(
sizeof(RedisMessage) * (reply_count - 1)); sizeof(RedisReply) * (reply_count - 1));
if (_other_replies == NULL) { if (_other_replies == NULL) {
LOG(ERROR) << "Fail to allocate RedisMessage[" << reply_count -1 << "]"; LOG(ERROR) << "Fail to allocate RedisReply[" << reply_count -1 << "]";
return PARSE_ERROR_ABSOLUTELY_WRONG; return PARSE_ERROR_ABSOLUTELY_WRONG;
} }
for (int i = 0; i < reply_count - 1; ++i) { for (int i = 0; i < reply_count - 1; ++i) {
new (&_other_replies[i]) RedisMessage(NULL); new (&_other_replies[i]) RedisReply(NULL);
} }
} }
for (int i = reply_size(); i < reply_count; ++i) { for (int i = reply_size(); i < reply_count; ++i) {
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "butil/strings/string_piece.h" #include "butil/strings/string_piece.h"
#include "butil/arena.h" #include "butil/arena.h"
#include "brpc/proto_base.pb.h" #include "brpc/proto_base.pb.h"
#include "brpc/redis_message.h" #include "brpc/redis_reply.h"
#include "brpc/parse_result.h" #include "brpc/parse_result.h"
#include "brpc/callback.h" #include "brpc/callback.h"
#include "brpc/socket.h" #include "brpc/socket.h"
...@@ -161,11 +161,11 @@ public: ...@@ -161,11 +161,11 @@ public:
int reply_size() const { return _nreply; } int reply_size() const { return _nreply; }
// Get index-th reply. If index is out-of-bound, nil reply is returned. // Get index-th reply. If index is out-of-bound, nil reply is returned.
const RedisMessage& reply(int index) const { const RedisReply& reply(int index) const {
if (index < reply_size()) { if (index < reply_size()) {
return (index == 0 ? _first_reply : _other_replies[index - 1]); return (index == 0 ? _first_reply : _other_replies[index - 1]);
} }
static RedisMessage redis_nil; static RedisReply redis_nil;
return redis_nil; return redis_nil;
} }
...@@ -203,8 +203,8 @@ private: ...@@ -203,8 +203,8 @@ private:
void SharedDtor(); void SharedDtor();
void SetCachedSize(int size) const; void SetCachedSize(int size) const;
RedisMessage _first_reply; RedisReply _first_reply;
RedisMessage* _other_replies; RedisReply* _other_replies;
butil::Arena _arena; butil::Arena _arena;
int _nreply; int _nreply;
mutable int _cached_size_; mutable int _cached_size_;
...@@ -226,7 +226,7 @@ public: ...@@ -226,7 +226,7 @@ public:
private: private:
typedef std::unordered_map<std::string, std::shared_ptr<RedisCommandHandler>> CommandMap; typedef std::unordered_map<std::string, std::shared_ptr<RedisCommandHandler>> CommandMap;
friend ParseResult ParseRedisMessage(butil::IOBuf*, Socket*, bool, const void*); friend ParseResult ParseRedisReply(butil::IOBuf*, Socket*, bool, const void*);
void CloneCommandMap(CommandMap* map); void CloneCommandMap(CommandMap* map);
CommandMap _command_map; CommandMap _command_map;
}; };
...@@ -247,7 +247,7 @@ public: ...@@ -247,7 +247,7 @@ public:
// command "set foo bar" corresponds to args[0] == "set", args[1] == "foo", // command "set foo bar" corresponds to args[0] == "set", args[1] == "foo",
// args[2] == "bar" and args[3] == nullptr. // args[2] == "bar" and args[3] == nullptr.
// `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_message.h for more usage. // Read brpc/src/redis_reply.h for more usage.
// Remember to call `done->Run()` when everything is set up into `output`. The return // Remember to call `done->Run()` when everything is set up into `output`. The return
// value should be RedisCommandHandler::OK for normal cases. If you want to implement // value should be RedisCommandHandler::OK for normal cases. If you want to implement
// transaction, return RedisCommandHandler::CONTINUE until server receives an ending // transaction, return RedisCommandHandler::CONTINUE until server receives an ending
...@@ -259,7 +259,7 @@ public: ...@@ -259,7 +259,7 @@ public:
// marker that ends the transaction. User may queue the commands and execute them // marker that ends the transaction. User may queue the commands and execute them
// all once an ending marker is received. // all once an ending marker is received.
virtual RedisCommandHandler::Result Run(const char* args[], virtual RedisCommandHandler::Result Run(const char* args[],
RedisMessage* output, RedisReply* output,
google::protobuf::Closure* done) = 0; google::protobuf::Closure* done) = 0;
// Whenever a tcp connection is established, a bunch of new handlers would be created // Whenever a tcp connection is established, a bunch of new handlers would be created
......
This diff is collapsed.
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