Skip to content

Commit

Permalink
polish some code
Browse files Browse the repository at this point in the history
  • Loading branch information
skyitachi committed Nov 11, 2023
1 parent f9802df commit 2ad17b0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
12 changes: 2 additions & 10 deletions src/commands/cmd_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,6 @@ class CommandJsonNumIncrBy : public Commander {
Status Execute(Server *svr, Connection *conn, std::string *output) override {
redis::Json json(svr->storage, conn->GetNamespace());

if (args_.size() != 4) {
return {Status::RedisExecErr, errWrongNumOfArguments};
}

JsonValue result = JsonValue::FromString("[]").GetValue();
auto s = json.NumIncrBy(args_[1], args_[2], args_[3], &result);
if (!s.ok()) {
Expand All @@ -420,10 +416,6 @@ class CommandJsonNumMultBy : public Commander {
Status Execute(Server *svr, Connection *conn, std::string *output) override {
redis::Json json(svr->storage, conn->GetNamespace());

if (args_.size() != 4) {
return {Status::RedisExecErr, errWrongNumOfArguments};
}

JsonValue result = JsonValue::FromString("[]").GetValue();
auto s = json.NumMultBy(args_[1], args_[2], args_[3], &result);
if (!s.ok()) {
Expand All @@ -448,7 +440,7 @@ REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandJsonSet>("json.set", 4, "write", 1, 1
MakeCmdAttr<CommandJsonObjkeys>("json.objkeys", -2, "read-only", 1, 1, 1),
MakeCmdAttr<CommandJsonArrPop>("json.arrpop", -2, "write", 1, 1, 1),
MakeCmdAttr<CommanderJsonArrIndex>("json.arrindex", -4, "read-only", 1, 1, 1),
MakeCmdAttr<CommandJsonNumIncrBy>("json.numincrby", -4, "write", 1, 1, 1),
MakeCmdAttr<CommandJsonNumMultBy>("json.nummultby", -4, "write", 1, 1, 1), );
MakeCmdAttr<CommandJsonNumIncrBy>("json.numincrby", 4, "write", 1, 1, 1),
MakeCmdAttr<CommandJsonNumMultBy>("json.nummultby", 4, "write", 1, 1, 1), );

} // namespace redis
3 changes: 1 addition & 2 deletions src/types/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,8 @@ struct JsonValue {
if (std::isinf(v)) {
status = {Status::RedisExecErr, "result is not number"};
return;
} else {
origin = v;
}
origin = v;
} else {
if (op == NumOpEnum::Incr) {
origin = NumOpIncrBy<int64_t>(origin.as_integer<int64_t>(), number.value.as_integer<int64_t>());
Expand Down
2 changes: 1 addition & 1 deletion src/types/redis_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ rocksdb::Status Json::numop(NumOpEnum op, const std::string &user_key, const std
JsonValue number;
auto number_res = JsonValue::FromString(value);
if (!number_res || !number_res.GetValue().value.is_number()) {
return rocksdb::Status::InvalidArgument("should be number");
return rocksdb::Status::InvalidArgument("should be a number");
}
number = std::move(number_res.GetValue());

Expand Down

0 comments on commit 2ad17b0

Please sign in to comment.