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

 ##########
 File path: src/brpc/redis.h
 ##########
 @@ -209,7 +212,51 @@ 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. To support a particular command, you should 
implement
+// the corresponding handler and call AddCommandHandler to install it.
+class RedisService {
+public:
+    typedef std::unordered_map<std::string, 
std::shared_ptr<RedisCommandHandler>> CommandMap;
+    virtual ~RedisService() {}
+
+    bool AddCommandHandler(const std::string& name, RedisCommandHandler* 
handler);
+    void CloneCommandMap(CommandMap* map);
+private:
+    CommandMap _command_map;
+};
+
+// The handler for a redis command. Run() and New() should be implemented
+// by user.
+//
+// For Run(), `args` is the redis command argument. For example,
+// "set foo bar" corresponds to args[0] == "set", args[1] == "foo" and
+// args[2] == "bar". `output` is the content that sent to client side,
+// which should be set by user.  Read brpc/src/redis_message.h for more usage.
+// User has to call `done->Run()` when everything is set up into `output`.
+//
+// For New(), whenever a tcp connection is established, a bunch of new handlers
+// would be created using New() of the corresponding handler and brpc makes 
sure
+// that all requests of the same command name from one connection would be 
redirected
+// to the same New()-ed command handler. All requests in one connection are
+// executed sequentially, just like what redis-server does.
+class RedisCommandHandler {
+public:
+    enum Result {
+        OK = 0,
+        CONTINUE = 1,
+    };
+    
+    ~RedisCommandHandler() {}
+    virtual RedisCommandHandler::Result Run(const char* args[],
 
 Review comment:
   不需要args长度??

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to