Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace atoi to Util::DecimalStringToNum #767

Merged
merged 4 commits into from
Aug 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4473,12 +4473,15 @@ class CommandCluster : public Commander {
if (subcommand_ == "keyslot" && args_.size() == 3) return Status::OK();
if (subcommand_ == "import") {
if (args.size() != 4) return Status(Status::RedisParseErr, errWrongNumOfArguments);
try {
slot_ = atoi(args[2].c_str());
state_ = static_cast<ImportStatus>(atoi(args[3].c_str()));
} catch (std::exception &e) {
return Status(Status::RedisParseErr, errValueNotInterger);
}
auto s = Util::DecimalStringToNum(args[2], &slot_);
if (!s.IsOK()) return s;

int64_t state;
s = Util::DecimalStringToNum(args[3], &state,
static_cast<int64_t>(kImportStart),
static_cast<int64_t>(kImportNone));
if (!s.IsOK()) return Status(Status::NotOK, "Invalid import state");
state_ = static_cast<ImportStatus>(state);
return Status::OK();
}
return Status(Status::RedisParseErr,
Expand Down Expand Up @@ -4535,7 +4538,7 @@ class CommandCluster : public Commander {
*output = Redis::Error(s.Msg());
}
} else if (subcommand_ == "import") {
Status s = svr->cluster_->ImportSlot(conn, slot_, state_);
Status s = svr->cluster_->ImportSlot(conn, static_cast<int>(slot_), state_);
if (s.IsOK()) {
*output = Redis::SimpleString("OK");
} else {
Expand All @@ -4549,7 +4552,7 @@ class CommandCluster : public Commander {

private:
std::string subcommand_;
int slot_ = -1;
int64_t slot_ = -1;
ImportStatus state_ = kImportNone;
};

Expand All @@ -4563,12 +4566,9 @@ class CommandClusterX : public Commander {
args_[2].size() == kClusterNodeIdLen) return Status::OK();
if (subcommand_ == "migrate") {
if (args.size() != 4) return Status(Status::RedisParseErr, errWrongNumOfArguments);
try {
slot_ = atoi(args[2].c_str());
dst_node_id_ = args[3];
} catch (std::exception &e) {
return Status(Status::RedisParseErr, errValueNotInterger);
}
auto s = Util::DecimalStringToNum(args[2], &slot_);
if (!s.IsOK()) return s;
dst_node_id_ = args[3];
return Status::OK();
}
if (subcommand_ == "setnodes" && args_.size() >= 4) {
Expand Down Expand Up @@ -4639,7 +4639,7 @@ class CommandClusterX : public Commander {
int64_t v = svr->cluster_->GetVersion();
*output = Redis::BulkString(std::to_string(v));
} else if (subcommand_ == "migrate") {
Status s = svr->cluster_->MigrateSlot(slot_, dst_node_id_);
Status s = svr->cluster_->MigrateSlot(static_cast<int>(slot_), dst_node_id_);
if (s.IsOK()) {
*output = Redis::SimpleString("OK");
} else {
Expand All @@ -4658,7 +4658,7 @@ class CommandClusterX : public Commander {
int slot_id_ = -1;
bool force_ = false;
std::string dst_node_id_;
int slot_ = -1;
int64_t slot_ = -1;
};

class CommandEval : public Commander {
Expand Down