diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc index 6540b5b36b2..70f199d81c5 100644 --- a/src/server/redis_connection.cc +++ b/src/server/redis_connection.cc @@ -27,6 +27,7 @@ #include "commands/commander.h" #include "fmt/format.h" +#include "string_util.h" #ifdef ENABLE_OPENSSL #include #endif @@ -289,6 +290,13 @@ void Connection::RecordProfilingSampleIfNeed(const std::string &cmd, uint64_t du svr_->GetPerfLog()->PushEntry(std::move(entry)); } +bool IsSpecialExclusiveCommand(const std::string &cmd_name, const std::vector &cmd_tokens, + Config *config) { + return (cmd_name == "config" && cmd_tokens.size() == 2 && util::EqualICase(cmd_tokens[1], "set")) || + (config->cluster_enabled && (cmd_name == "clusterx" || cmd_name == "cluster") && cmd_tokens.size() >= 2 && + Cluster::SubCommandIsExecExclusive(cmd_tokens[1])); +} + void Connection::ExecuteCommands(std::deque *to_process_cmds) { Config *config = svr_->GetConfig(); std::string reply, password = config->requirepass; @@ -330,10 +338,7 @@ void Connection::ExecuteCommands(std::deque *to_process_cmds) { // Otherwise, we just use 'ConcurrencyGuard' to allow all workers to execute commands at the same time. if (IsFlagEnabled(Connection::kMultiExec) && attributes->name != "exec") { // No lock guard, because 'exec' command has acquired 'WorkExclusivityGuard' - } else if (attributes->IsExclusive() || - (cmd_name == "config" && cmd_tokens.size() == 2 && !strcasecmp(cmd_tokens[1].c_str(), "set")) || - (config->cluster_enabled && (cmd_name == "clusterx" || cmd_name == "cluster") && - cmd_tokens.size() >= 2 && Cluster::SubCommandIsExecExclusive(cmd_tokens[1]))) { + } else if (attributes->IsExclusive() || IsSpecialExclusiveCommand(cmd_name, cmd_tokens, config)) { exclusivity = svr_->WorkExclusivityGuard(); // When executing lua script commands that have "exclusive" attribute, we need to know current connection,