liumh8 commented on a change in pull request #1128:
URL: https://github.com/apache/incubator-brpc/pull/1128#discussion_r434983839



##########
File path: src/brpc/redis.cpp
##########
@@ -437,19 +437,21 @@ std::ostream& operator<<(std::ostream& os, const 
RedisResponse& response) {
 }
 
 bool RedisService::AddCommandHandler(const std::string& name, 
RedisCommandHandler* handler) {
-    std::string lcname = StringToLowerASCII(name);
-    auto it = _command_map.find(lcname);
+    butil::StringPiece name_piece(name);
+    auto it = _command_map.find(name_piece);
     if (it != _command_map.end()) {
         LOG(ERROR) << "redis command name=" << name << " exist";
         return false;
     }
-    _command_map[lcname] = handler;
+    
+    _all_commands.push_back(name);
+    name_piece = _all_commands.back();

Review comment:
       这个是因为FindCommandHandler要通过StringPiece查找Handler,`typedef 
std::unordered_map<butil::StringPiece, RedisCommandHandler*, StringPieceHasher> 
CommandMap` 
所以这个map存的是StringPiece,为了使这个StringPiece所指向的字符串内存没有被释放,所以用了个std::list<string\>来保存




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



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

Reply via email to