From a1cc7c263abde54a85bd5b58168e1a4069d9671c Mon Sep 17 00:00:00 2001 From: otheng <qnade@naver.com> Date: Mon, 7 Oct 2024 02:40:58 +0900 Subject: [PATCH] Reuse `obey_client` variable in `processCommand()` function (#1101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’ve prepared a minor fix for `processCommand()` function. In `processCommand()`, the `obey_client` variable is created, but some conditional statements call the `mustObeyClient()` function instead of reusing `obey_client`. I’ve modified these statements to `reuse obey_client`. Since I’m relatively new to Redis, please let me know if there are any reasons why the conditional statements need to call `mustObeyClient()` again. Thank you for taking the time to review my PR. Signed-off-by: otheng03 <07c00h@gmail.com> --- src/server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server.c b/src/server.c index 56a49c85a..d9f7d7384 100644 --- a/src/server.c +++ b/src/server.c @@ -3891,7 +3891,7 @@ int processCommand(client *c) { (c->cmd->proc == execCommand && (c->mstate.cmd_flags & (CMD_WRITE | CMD_MAY_REPLICATE))); int is_deny_async_loading_command = (cmd_flags & CMD_NO_ASYNC_LOADING) || (c->cmd->proc == execCommand && (c->mstate.cmd_flags & CMD_NO_ASYNC_LOADING)); - int obey_client = mustObeyClient(c); + const int obey_client = mustObeyClient(c); if (authRequired(c)) { /* AUTH and HELLO and no auth commands are valid even in @@ -3924,7 +3924,7 @@ int processCommand(client *c) { * However we don't perform the redirection if: * 1) The sender of this command is our primary. * 2) The command has no key arguments. */ - if (server.cluster_enabled && !mustObeyClient(c) && + if (server.cluster_enabled && !obey_client && !(!(c->cmd->flags & CMD_MOVABLE_KEYS) && c->cmd->key_specs_num == 0 && c->cmd->proc != execCommand)) { int error_code; clusterNode *n = getNodeByQuery(c, c->cmd, c->argv, c->argc, &c->slot, &error_code); @@ -3941,7 +3941,7 @@ int processCommand(client *c) { } } - if (!server.cluster_enabled && c->capa & CLIENT_CAPA_REDIRECT && server.primary_host && !mustObeyClient(c) && + if (!server.cluster_enabled && c->capa & CLIENT_CAPA_REDIRECT && server.primary_host && !obey_client && (is_write_command || (is_read_command && !c->flag.readonly))) { if (server.failover_state == FAILOVER_IN_PROGRESS) { /* During the FAILOVER process, when conditions are met (such as