jamesge commented on a change in pull request #972: Redis server protocol
URL: https://github.com/apache/incubator-brpc/pull/972#discussion_r359139447
 
 

 ##########
 File path: src/brpc/redis.h
 ##########
 @@ -209,7 +213,74 @@ class RedisResponse : public ::google::protobuf::Message {
 std::ostream& operator<<(std::ostream& os, const RedisRequest&);
 std::ostream& operator<<(std::ostream& os, const RedisResponse&);
 
-} // namespace brpc
+class RedisCommandHandler;
+
+// Implement this class and assign an instance to ServerOption.redis_service
+// to enable redis support. 
+class RedisService {
+public:
+    typedef std::unordered_map<std::string, RedisCommandHandler*> CommandMap;
+    virtual ~RedisService() {}
+    
+    // Call this function to register `handler` that can handle command `name`.
+    bool AddCommandHandler(const std::string& name, RedisCommandHandler* 
handler);
+
+    // This function should not be touched by user and used by brpc deverloper 
only.
+    RedisCommandHandler* FindCommandHandler(const std::string& name);
+private:
+    CommandMap _command_map;
+};
+
+// The Command handler for a redis request. User should impletement Run().
+class RedisCommandHandler {
+public:
+    enum Result {
+        OK = 0,
+        CONTINUE = 1,
+        BATCHED = 2,
+    };
+    ~RedisCommandHandler() {}
+
+    // Once Server receives commands, it will first find the corresponding 
handlers and
+    // call them sequentially(one by one) according to the order that requests 
arrive,
+    // just like what redis-server does.
+    // `args_len` is the length of request command.
+    // `args' is the array of request command. For example, "set somekey 
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.
+    // Read brpc/src/redis_reply.h for more usage.
+    // `is_last' indicates whether the commands is the last command of this 
batch. If user
+    // want to do some batch processing, user should buffer the command and 
return
+    // RedisCommandHandler::BATCHED. Once `is_last' is true, run all the 
commands and
+    // set `output' to be an array and set all the results to the 
corresponding element
+    // of array.
+    //
+    // The return value should be RedisCommandHandler::OK for normal cases. If 
you want
+    // to implement transaction, return RedisCommandHandler::CONTINUE once 
server receives
+    // an start marker and brpc will call MultiTransactionHandler() to new a 
transaction
+    // handler that all the following commands are sent to this tranction 
handler until
+    // it returns Result::OK. Read the comment below.
+    virtual RedisCommandHandler::Result Run(int args_len, const char* args[],
+                                            brpc::RedisReply* output,
+                                            bool is_last) = 0;
 
+    // This function is called to new a transaction handler once Run() returns
+    // RedisCommandHandler::CONTINUE. All the following commands are sent to 
this
+    // handler until it return Result::OK. For example, for command "multi; 
set k1 v1;
+    // set k2 v2; set k3 v3; exec":
+    // 1) In Run(), command is "multi", so return 
RedisCommandHandler::CONTINUE, and
+    // brpc calls NewTransactionHandler() to new a handler tran_handler.
 
 Review comment:
   tran_handler是什么东西?a handler tran_handler又是什么?就叫a 
transaction_handler没有问题把?保持一致性对后续维护是很重要的。

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to