Commit 0c96ecef authored by zhujiashun's avatar zhujiashun

redis_server_protocol: rename RedisReply to RedisMessage

parent 978814fe
...@@ -54,7 +54,7 @@ struct InputResponse : public InputMessageBase { ...@@ -54,7 +54,7 @@ struct InputResponse : public InputMessageBase {
}; };
struct ExecutionQueueContext { struct ExecutionQueueContext {
RedisReply message; RedisMessage message;
SocketId socket_id; SocketId socket_id;
butil::Arena arena; butil::Arena arena;
}; };
...@@ -72,7 +72,7 @@ int Consume(void* meta, bthread::TaskIterator<ExecutionQueueContext*>& iter) { ...@@ -72,7 +72,7 @@ int Consume(void* meta, bthread::TaskIterator<ExecutionQueueContext*>& iter) {
LOG(WARNING) << "Fail to address redis socket"; LOG(WARNING) << "Fail to address redis socket";
continue; continue;
} }
RedisReply output; RedisMessage output;
conn->OnRedisMessage(ctx->message, &output, &ctx->arena); conn->OnRedisMessage(ctx->message, &output, &ctx->arena);
butil::IOBuf sendbuf; butil::IOBuf sendbuf;
output.SerializeToIOBuf(&sendbuf); output.SerializeToIOBuf(&sendbuf);
...@@ -132,7 +132,7 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket, ...@@ -132,7 +132,7 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
socket->reset_parsing_context(ctx); socket->reset_parsing_context(ctx);
} }
std::unique_ptr<ExecutionQueueContext> task(new ExecutionQueueContext); std::unique_ptr<ExecutionQueueContext> task(new ExecutionQueueContext);
RedisReply message; RedisMessage message;
ParseError err = message.ConsumePartialIOBuf(*source, &task->arena); ParseError err = message.ConsumePartialIOBuf(*source, &task->arena);
if (err != PARSE_OK) { if (err != PARSE_OK) {
return MakeParseError(err); return MakeParseError(err);
...@@ -178,7 +178,7 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket, ...@@ -178,7 +178,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_REPLY_STATUS && !(msg->response.reply(0).type() == brpc::REDIS_MESSAGE_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;
} }
RedisReply* new_others = RedisMessage* new_others =
(RedisReply*)_arena.allocate(sizeof(RedisReply) * (new_nreply - 1)); (RedisMessage*)_arena.allocate(sizeof(RedisMessage) * (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) RedisReply; new (new_others + i) RedisMessage;
} }
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 = (RedisReply*)_arena.allocate( _other_replies = (RedisMessage*)_arena.allocate(
sizeof(RedisReply) * (reply_count - 1)); sizeof(RedisMessage) * (reply_count - 1));
if (_other_replies == NULL) { if (_other_replies == NULL) {
LOG(ERROR) << "Fail to allocate RedisReply[" << reply_count -1 << "]"; LOG(ERROR) << "Fail to allocate RedisMessage[" << 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]) RedisReply; new (&_other_replies[i]) RedisMessage;
} }
} }
for (int i = reply_size(); i < reply_count; ++i) { for (int i = reply_size(); i < reply_count; ++i) {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,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_reply.h" #include "brpc/redis_message.h"
#include "brpc/parse_result.h" #include "brpc/parse_result.h"
namespace brpc { namespace brpc {
...@@ -157,11 +157,11 @@ public: ...@@ -157,11 +157,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 RedisReply& reply(int index) const { const RedisMessage& 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 RedisReply redis_nil; static RedisMessage redis_nil;
return redis_nil; return redis_nil;
} }
...@@ -199,8 +199,8 @@ private: ...@@ -199,8 +199,8 @@ private:
void SharedDtor(); void SharedDtor();
void SetCachedSize(int size) const; void SetCachedSize(int size) const;
RedisReply _first_reply; RedisMessage _first_reply;
RedisReply* _other_replies; RedisMessage* _other_replies;
butil::Arena _arena; butil::Arena _arena;
int _nreply; int _nreply;
mutable int _cached_size_; mutable int _cached_size_;
...@@ -212,8 +212,8 @@ std::ostream& operator<<(std::ostream& os, const RedisResponse&); ...@@ -212,8 +212,8 @@ std::ostream& operator<<(std::ostream& os, const RedisResponse&);
class RedisConnection { class RedisConnection {
public: public:
virtual ~RedisConnection() {} virtual ~RedisConnection() {}
virtual void OnRedisMessage(const RedisReply& message, virtual void OnRedisMessage(const RedisMessage& message,
RedisReply* output, butil::Arena* arena) = 0; RedisMessage* output, butil::Arena* arena) = 0;
}; };
class RedisService { class RedisService {
......
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