PragmaTwice commented on code in PR #1841:
URL: https://github.com/apache/kvrocks/pull/1841#discussion_r1375939432
##########
src/commands/cmd_json.cc:
##########
@@ -204,11 +204,62 @@ class CommandJsonArrLen : public Commander {
}
};
+class CommandJsonStrAppend : public Commander {
+ public:
+ Status Execute(Server *svr, Connection *conn, std::string *output) override {
+ redis::Json json(svr->storage, conn->GetNamespace());
+
+ // path default, if not provided
+ std::string path = "$";
+ if (args_.size() == 4) {
+ path = args_[2];
+ }
+ std::vector<uint64_t> results;
+ auto s = json.StrAppend(args_[1], path, args_[3], results);
+ if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+
+ *output = IntegerArray(results);
+ return Status::OK();
+ }
+
+ static std::string IntegerArray(const std::vector<uint64_t> &values, bool
output_nil_for_negative = true) {
+ std::string result = "*" + std::to_string(values.size()) + CRLF;
+ for (const auto &value : values) {
+ if (value == (uint64_t)-1 and output_nil_for_negative) {
Review Comment:
`(uint64_t)-1` is NOT a negative number. You can just remove
`output_nil_for_negative`.
--
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]