This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 6350d729 Use EqualICase instead of strcasecmp in cluster (#1640)
6350d729 is described below
commit 6350d72902a48ce73f9d3fcd39ac795eb765385e
Author: Twice <[email protected]>
AuthorDate: Sun Aug 6 18:26:17 2023 +0800
Use EqualICase instead of strcasecmp in cluster (#1640)
---
src/cluster/cluster.cc | 14 ++++----------
src/commands/cmd_cluster.cc | 4 ++--
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc
index b1596928..e345dd92 100644
--- a/src/cluster/cluster.cc
+++ b/src/cluster/cluster.cc
@@ -53,14 +53,8 @@ Cluster::Cluster(Server *svr, std::vector<std::string>
binds, int port)
// cluster data, so these commands should be executed exclusively, and
ReadWriteLock
// also can guarantee accessing data is safe.
bool Cluster::SubCommandIsExecExclusive(const std::string &subcommand) {
- if (strcasecmp("setnodes", subcommand.c_str()) == 0) {
- return true;
- } else if (strcasecmp("setnodeid", subcommand.c_str()) == 0) {
- return true;
- } else if (strcasecmp("setslot", subcommand.c_str()) == 0) {
- return true;
- } else if (strcasecmp("import", subcommand.c_str()) == 0) {
- return true;
+ for (auto v : {"setnodes", "setnodeid", "setslot", "import"}) {
+ if (util::EqualICase(v, subcommand)) return true;
}
return false;
}
@@ -667,9 +661,9 @@ Status Cluster::parseClusterNodes(const std::string
&nodes_str, ClusterNodes *no
// 4) role
int role = 0;
- if (strcasecmp(fields[3].c_str(), "master") == 0) {
+ if (util::EqualICase(fields[3], "master")) {
role = kClusterMaster;
- } else if (strcasecmp(fields[3].c_str(), "slave") == 0 ||
strcasecmp(fields[3].c_str(), "replica") == 0) {
+ } else if (util::EqualICase(fields[3], "slave") ||
util::EqualICase(fields[3], "replica")) {
role = kClusterSlave;
} else {
return {Status::ClusterInvalidInfo, "Invalid cluster node role"};
diff --git a/src/commands/cmd_cluster.cc b/src/commands/cmd_cluster.cc
index c4026879..e34186ee 100644
--- a/src/commands/cmd_cluster.cc
+++ b/src/commands/cmd_cluster.cc
@@ -172,7 +172,7 @@ class CommandClusterX : public Commander {
if (args_.size() == 4) return Status::OK();
- if (args_.size() == 5 && strcasecmp(args_[4].c_str(), "force") == 0) {
+ if (args_.size() == 5 && util::EqualICase(args_[4], "force")) {
force_ = true;
return Status::OK();
}
@@ -187,7 +187,7 @@ class CommandClusterX : public Commander {
return s;
}
- if (strcasecmp(args_[3].c_str(), "node") != 0) {
+ if (!util::EqualICase(args_[3], "node")) {
return {Status::RedisParseErr, "Invalid setslot options"};
}