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 af184201 Improve code style for auth in ExecuteCommands (#2096)
af184201 is described below
commit af1842017cba2a0f36d3f2288805a2ea2d3a630a
Author: Twice <[email protected]>
AuthorDate: Sat Feb 10 22:26:02 2024 +0900
Improve code style for auth in ExecuteCommands (#2096)
---
src/server/redis_connection.cc | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc
index 80904507..19bcbceb 100644
--- a/src/server/redis_connection.cc
+++ b/src/server/redis_connection.cc
@@ -428,30 +428,29 @@ void
Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
}
auto current_cmd = std::move(*cmd_s);
- if (GetNamespace().empty()) {
- if (!password.empty() && util::ToLower(cmd_tokens.front()) != "auth" &&
- util::ToLower(cmd_tokens.front()) != "hello") {
- Reply(redis::Error("NOAUTH Authentication required."));
- continue;
- }
+ const auto attributes = current_cmd->GetAttributes();
+ auto cmd_name = attributes->name;
+ auto cmd_flags = attributes->GenerateFlags(cmd_tokens);
- if (password.empty()) {
+ if (GetNamespace().empty()) {
+ if (!password.empty()) {
+ if (cmd_name != "auth" && cmd_name != "hello") {
+ Reply(redis::Error("NOAUTH Authentication required."));
+ continue;
+ }
+ } else {
BecomeAdmin();
SetNamespace(kDefaultNamespace);
}
}
- const auto attributes = current_cmd->GetAttributes();
- auto cmd_name = attributes->name;
- auto cmd_flags = attributes->GenerateFlags(cmd_tokens);
-
std::shared_lock<std::shared_mutex> concurrency; // Allow concurrency
std::unique_lock<std::shared_mutex> exclusivity; // Need exclusivity
// If the command needs to process exclusively, we need to get
'ExclusivityGuard'
// that can guarantee other threads can't come into critical zone, such as
DEBUG,
// CLUSTER subcommand, CONFIG SET, MULTI, LUA (in the immediate future).
// Otherwise, we just use 'ConcurrencyGuard' to allow all workers to
execute commands at the same time.
- if (is_multi_exec && attributes->name != "exec") {
+ if (is_multi_exec && cmd_name != "exec") {
// No lock guard, because 'exec' command has acquired
'WorkExclusivityGuard'
} else if (cmd_flags & kCmdExclusive) {
exclusivity = srv_->WorkExclusivityGuard();
@@ -490,8 +489,7 @@ void Connection::ExecuteCommands(std::deque<CommandTokens>
*to_process_cmds) {
}
if (is_multi_exec && (cmd_flags & kCmdNoMulti)) {
- std::string no_multi_err = "ERR Can't execute " + attributes->name + "
in MULTI";
- Reply(redis::Error(no_multi_err));
+ Reply(redis::Error("ERR Can't execute " + cmd_name + " in MULTI"));
multi_error_ = true;
continue;
}