git-hulk commented on code in PR #1841:
URL: https://github.com/apache/kvrocks/pull/1841#discussion_r1366907527


##########
src/types/json.h:
##########
@@ -65,6 +66,29 @@ struct JsonValue {
     return Status::OK();
   }
 
+  Status Append(std::string_view path, const std::string &append_value, 
std::vector<uint64_t> &append_cnt) {
+    try {
+      auto append_trimmed = util::Trim(append_value, "\"");
+      jsoncons::jsonpath::json_replace(value, path, [&append_trimmed, 
&append_cnt](const std::string & /*path*/, jsoncons::json &origin) {
+        uint64_t len = 0;
+        if (origin.is_string()) {
+          auto origin_str = origin.to_string();
+          // need trim "
+          auto origin_trimmed = util::Trim(origin_str, "\"");
+          len = origin_trimmed.length() + append_trimmed.length();
+          std::string new_value;
+          
new_value.append("\"").append(origin_trimmed).append(append_trimmed).append("\"");
+          origin = jsoncons::json::parse(new_value);
+        }
+        append_cnt.push_back(len);

Review Comment:
   ```suggestion
           } else {
             append_cnt.push_back(0);
           }
   ```



##########
src/types/redis_json.cc:
##########
@@ -117,4 +117,39 @@ rocksdb::Status Json::Get(const std::string &user_key, 
const std::vector<std::st
   return rocksdb::Status::OK();
 }
 
+rocksdb::Status Json::StrAppend(const std::string &user_key, const 
std::vector<std::string> &paths, const std::string &value, 
std::vector<uint64_t> &append_cnt) {

Review Comment:
   Path should be std::string?



##########
src/commands/cmd_json.cc:
##########
@@ -52,7 +52,24 @@ class CommandJsonGet : public Commander {
   }
 };
 
+class CommandJsonStrAppend : public Commander {
+public:
+    Status Execute(Server *svr, Connection *conn, std::string *output) 
override {
+      redis::Json json(svr->storage, conn->GetNamespace());
+
+      std::vector<uint64_t> cnt;

Review Comment:
   can rename cnt to others like results because cnt looks like a single value.



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