wwbmmm commented on code in PR #2902:
URL: https://github.com/apache/brpc/pull/2902#discussion_r1975328043


##########
src/brpc/redis.h:
##########
@@ -235,8 +261,14 @@ class RedisCommandHandler {
     // it returns REDIS_CMD_HANDLED. Read the comment below.
     virtual RedisCommandHandlerResult Run(const 
std::vector<butil::StringPiece>& args,
                                           brpc::RedisReply* output,
-                                          bool flush_batched) = 0;
-
+                                          bool flush_batched) {
+        return REDIS_CMD_HANDLED;                                    
+    };
+    virtual RedisCommandHandlerResult Run(RedisConnContext* ctx, const 
std::vector<butil::StringPiece>& args,

Review Comment:
   一行一个参数



##########
src/brpc/redis.h:
##########
@@ -209,7 +211,31 @@ enum RedisCommandHandlerResult {
     REDIS_CMD_CONTINUE = 1,
     REDIS_CMD_BATCHED = 2,
 };
-
+class RedisCommandParser;

Review Comment:
   类定义之间加空行,下同



##########
example/redis_c++/redis_server.cpp:
##########
@@ -30,22 +30,38 @@
 #include <butil/time.h>
 
 DEFINE_int32(port, 6379, "TCP Port of this server");
-
 class RedisServiceImpl : public brpc::RedisService {
 public:
-    bool Set(const std::string& key, const std::string& value) {
+    RedisServiceImpl() {
+        _user_password["db1"] = "123456";
+        _user_password["db2"] = "123456";
+        _db_map["db1"].resize(kHashSlotNum);
+        _db_map["db2"].resize(kHashSlotNum);
+    }
+    bool Set(const std::string& db_name, const std::string& key, const 
std::string& value) {

Review Comment:
   方法之间添加空行,下同



##########
src/brpc/policy/redis_protocol.cpp:
##########
@@ -134,13 +113,6 @@ int ConsumeCommand(RedisConnContext* ctx,
     return 0;
 }
 
-// ========== impl of RedisConnContext ==========
-
-RedisConnContext::~RedisConnContext() { }
-
-void RedisConnContext::Destroy() {
-    delete this;
-}
 
 // ========== impl of RedisConnContext ==========

Review Comment:
   这一行也可以删了



##########
src/brpc/redis.h:
##########
@@ -209,7 +211,31 @@ enum RedisCommandHandlerResult {
     REDIS_CMD_CONTINUE = 1,
     REDIS_CMD_BATCHED = 2,
 };
-
+class RedisCommandParser;
+// This class is as parsing_context in socket.
+class RedisConnContext : public Destroyable  {
+public:
+    explicit RedisConnContext(const RedisService* rs)
+        : redis_service(rs)
+        , batched_size(0) {}
+
+    ~RedisConnContext();
+    // @Destroyable
+    void Destroy() override;
+
+    const RedisService* redis_service;
+    // If user starts a transaction, transaction_handler indicates the
+    // handler pointer that runs the transaction command.
+    std::unique_ptr<RedisCommandHandler> transaction_handler;
+    // >0 if command handler is run in batched mode.
+    int batched_size;
+    // If user is authenticated, user_name and password are set.
+    // Keep auth info in RedisConnContext to distinguish diffrent users( or 
diffrent db).
+    std::string user_name;

Review Comment:
   框架中定义了user_name和password这两个字段,却没有使用它,不太合适。
   可以考虑定义成一个自定义类型,比如Destroyable* data,然后用户代码中自己定义这个数据。



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

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to