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

 ##########
 File path: src/brpc/redis.h
 ##########
 @@ -209,6 +209,44 @@ class RedisResponse : public ::google::protobuf::Message {
 std::ostream& operator<<(std::ostream& os, const RedisRequest&);
 std::ostream& operator<<(std::ostream& os, const RedisResponse&);
 
+enum RedisCommandResult {
+    REDIS_COMMAND_OK = 0,
+    REDIS_COMMAND_CONTINUE = 1,
+    REDIS_COMMAND_ERROR = 2,
+};
+
+// 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.
+// `arena` is the memory arena that `output` would use.
+// For New(), whenever a tcp connection is established, all handlers would
+// be cloned and brpc makes sure that all requests of the same command name
+// from one connection would be sent to the same command handler. All requests
+// in one connection are executed sequentially, just like what redis-server 
does.
+class RedisCommandHandler {
+public:
+    ~RedisCommandHandler() {}
+    virtual RedisCommandResult Run(const std::vector<const char*>& args,
+            RedisMessage* output, butil::Arena* arena) = 0;
 
 Review comment:
   这个arena要封装掉,你让用户每次set都要填这个arena本来就是一件令用户迷惑的事情。
   这里要真正回答的问题是:command 
handler是否要支持异步。异步指的是调用完Run时command还没处理结束,真正处理结束时会调用框架传入的done,和service接口是类似的,arena可以放done里一并管理。如果你没有递done,那么就意味着这个接口是同步的,arena完全可以由框架代管。至于担心RedisMessage复制导致问题,禁用掉复制就行了。

----------------------------------------------------------------
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