2rueSid commented on code in PR #1856:
URL: https://github.com/apache/kvrocks/pull/1856#discussion_r1371837614
##########
src/commands/cmd_json.cc:
##########
@@ -171,10 +171,44 @@ class CommandJsonClear : public Commander {
}
};
+class CommandJsonArrLen : public Commander {
+ public:
+ Status Execute(Server *svr, Connection *conn, std::string *output) override {
+ redis::Json json(svr->storage, conn->GetNamespace());
+
+ std::string path = "$";
+ if (args_.size() == 3) {
+ path = args_[2];
+ } else if (args_.size() > 3) {
+ return {Status::RedisExecErr, "The number of arguments is more than
expected"};
+ }
+
+ std::vector<uint64_t> results;
+ auto s = json.ArrLen(args_[1], path, results);
+ if (s.IsNotFound()) {
+ *output = redis::NilString();
+ return Status::OK();
+ }
+ if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+
+ *output = redis::MultiLen(results.size());
+ for (size_t len : results) {
+ if (len >= 0) {
+ *output += redis::Integer(len);
+ } else {
+ *output += redis::NilString();
+ }
+ }
+
+ return Status::OK();
+ }
+};
+
REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandJsonSet>("json.set", 4, "write", 1,
1, 1),
MakeCmdAttr<CommandJsonGet>("json.get", -2,
"read-only", 1, 1, 1),
MakeCmdAttr<CommandJsonType>("json.type", -2,
"read-only", 1, 1, 1),
MakeCmdAttr<CommandJsonArrAppend>("json.arrappend",
-4, "write", 1, 1, 1),
- MakeCmdAttr<CommandJsonClear>("json.clear", -2,
"write", 1, 1, 1), );
+ MakeCmdAttr<CommandJsonClear>("json.clear", -2,
"write", 1, 1, 1),
+ MakeCmdAttr<CommandJsonClear>("json.arrlen", -2,
"read-only", 1, 1, 1), );
Review Comment:
I guess that it should be this:
```cpp
MakeCmdAttr<CommandJsonClear>("json.clear", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandJsonArrLen>("json.arrlen", -2, "read-only", 1, 1, 1), );
```
instead of:
```cpp
MakeCmdAttr<CommandJsonClear>("json.clear", -2, "write", 1, 1, 1),
MakeCmdAttr<CommandJsonClear>("json.arrlen", -2, "read-only", 1, 1, 1), );
```
--
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]