mapleFU commented on code in PR #1837:
URL: https://github.com/apache/kvrocks/pull/1837#discussion_r1365508230


##########
src/commands/cmd_json.cc:
##########
@@ -52,7 +52,35 @@ class CommandJsonGet : public Commander {
   }
 };
 
+class CommandJsonArrAppend : public Commander {
+ public:
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::Json json(svr->storage, conn->GetNamespace());
+
+    std::vector<uint64_t> result_count;
+
+    auto s = json.ArrAppend(args_[1], args_[2], {args_.begin() + 3, 
args_.end()}, &result_count);
+    if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+
+    if (result_count.empty()) {

Review Comment:
   I guess you can:
   
   ```
   std::vector<std::string> results;
   results.reserve(result_count.size());
       for (uint64_t c : result_count) {
         if (c != 0) {
           results.push_back(redis::Integer(c));
         } else {
           results.push_back(redis::NilString());
         }
       }
      *output = MultiBulkString(...);
   ```
   
   (The code above might failed to compile or doesn't have right style, just to 
show the way here.)
   
   So that we can simplify our code, and use `MultiBulkString` to handle the 
return value with zero counts.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to