jihuayu commented on code in PR #2228:
URL: https://github.com/apache/kvrocks/pull/2228#discussion_r1555097596
##########
src/types/redis_json.cc:
##########
@@ -548,6 +548,67 @@ std::vector<rocksdb::Status> Json::MGet(const
std::vector<std::string> &user_key
return statuses;
}
+rocksdb::Status Json::MSet(const std::vector<std::string> &user_keys, const
std::vector<std::string> &paths,
+ const std::vector<std::string> &values) {
+ std::optional<MultiLockGuard> guard;
+ std::vector<std::string> lock_keys;
+ lock_keys.reserve(user_keys.size());
+ for (const auto &user_key : user_keys) {
+ std::string ns_key = AppendNamespacePrefix(user_key);
+ lock_keys.emplace_back(std::move(ns_key));
+ }
+ guard.emplace(storage_->GetLockManager(), lock_keys);
+
+ auto batch = storage_->GetWriteBatchBase();
+ WriteBatchLogData log_data(kRedisJson);
+ batch->PutLogData(log_data.Encode());
+
+ for (size_t i = 0; i < user_keys.size(); i++) {
+ std::string ns_key = AppendNamespacePrefix(user_keys[i]);
+
+ auto json_res = JsonValue::FromString(values[i],
storage_->GetConfig()->json_max_nesting_depth);
+ if (!json_res) return rocksdb::Status::InvalidArgument(json_res.Msg());
+
+ JsonMetadata metadata;
+ JsonValue value;
+ auto s = read(ns_key, &metadata, &value);
+
+ if (s.IsNotFound()) {
Review Comment:
Some
[Sonarcloud
report](https://sonarcloud.io/project/issues?resolved=false&pullRequest=2228&id=apache_kvrocks&open=AY65WAwxQLtepdGeR4C7)
##########
src/commands/cmd_json.cc:
##########
@@ -594,6 +594,32 @@ class CommandJsonMGet : public Commander {
}
};
+class CommandJsonMSet : public Commander {
+ public:
+ Status Execute(Server *svr, Connection *conn, std::string *output) override {
+ if ((args_.size() - 1) % 3 != 0) {
+ return {Status::RedisExecErr, errWrongNumOfArguments};
+ }
+
+ redis::Json json(svr->storage, conn->GetNamespace());
+
+ std::vector<std::string> user_keys;
+ std::vector<std::string> paths;
+ std::vector<std::string> values;
+ for (size_t i = 0; i < (args_.size() - 1) / 3; i++) {
+ user_keys.emplace_back(args_[i * 3 + 1]);
+ paths.emplace_back(args_[i * 3 + 2]);
+ values.emplace_back(args_[i * 3 + 3]);
+ }
+
+ auto s = json.MSet(user_keys, paths, values);
+ if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
Review Comment:
Can you change those codes to make Sonarcloud happy?
[Sonarcloud
report](https://sonarcloud.io/project/issues?resolved=false&pullRequest=2228&id=apache_kvrocks&open=AY65WAx3QLtepdGeR4C8&tab=code)
--
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]