From ffa007704122a3e4947252f3dbbef3e2be4b6033 Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Tue, 14 Jun 2022 08:48:08 +0300 Subject: [PATCH] Allow ECHO in loading and stale modes (#10853) I noticed that scripting.tcl uses INFO from within a script and thought it's an overkill and concluded it's nicer to use another CMD_STALE command, decided to use ECHO, and then noticed it's not at all allowed in stale mode. probably overlooked at #6843 --- src/commands.c | 2 +- src/commands/echo.json | 2 ++ tests/unit/scripting.tcl | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/commands.c b/src/commands.c index 7ea796470..d2364b0ab 100644 --- a/src/commands.c +++ b/src/commands.c @@ -7175,7 +7175,7 @@ struct redisCommand redisCommandTable[] = { /* connection */ {"auth","Authenticate to the server","O(N) where N is the number of passwords defined for the user","1.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CONNECTION,AUTH_History,AUTH_tips,authCommand,-2,CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_FAST|CMD_NO_AUTH|CMD_SENTINEL|CMD_ALLOW_BUSY,ACL_CATEGORY_CONNECTION,.args=AUTH_Args}, {"client","A container for client connection commands","Depends on subcommand.","2.4.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CONNECTION,CLIENT_History,CLIENT_tips,NULL,-2,CMD_SENTINEL,0,.subcommands=CLIENT_Subcommands}, -{"echo","Echo the given string","O(1)","1.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CONNECTION,ECHO_History,ECHO_tips,echoCommand,2,CMD_FAST,ACL_CATEGORY_CONNECTION,.args=ECHO_Args}, +{"echo","Echo the given string","O(1)","1.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CONNECTION,ECHO_History,ECHO_tips,echoCommand,2,CMD_LOADING|CMD_STALE|CMD_FAST,ACL_CATEGORY_CONNECTION,.args=ECHO_Args}, {"hello","Handshake with Redis","O(1)","6.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CONNECTION,HELLO_History,HELLO_tips,helloCommand,-1,CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_FAST|CMD_NO_AUTH|CMD_SENTINEL|CMD_ALLOW_BUSY,ACL_CATEGORY_CONNECTION,.args=HELLO_Args}, {"ping","Ping the server","O(1)","1.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CONNECTION,PING_History,PING_tips,pingCommand,-1,CMD_FAST|CMD_SENTINEL,ACL_CATEGORY_CONNECTION,.args=PING_Args}, {"quit","Close the connection","O(1)","1.0.0",CMD_DOC_NONE,NULL,NULL,COMMAND_GROUP_CONNECTION,QUIT_History,QUIT_tips,quitCommand,-1,CMD_ALLOW_BUSY|CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_FAST|CMD_NO_AUTH,ACL_CATEGORY_CONNECTION}, diff --git a/src/commands/echo.json b/src/commands/echo.json index a641bd35d..f38d10bc5 100644 --- a/src/commands/echo.json +++ b/src/commands/echo.json @@ -7,6 +7,8 @@ "arity": 2, "function": "echoCommand", "command_flags": [ + "LOADING", + "STALE", "FAST" ], "acl_categories": [ diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index 6e43ca264..a91eef7e9 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -1599,19 +1599,19 @@ start_server {tags {"scripting"}} { } 1 x } - assert_match {*redis_version*} [ + assert_match {foobar} [ r eval {#!lua flags=allow-stale,no-writes - return redis.call('info','server') + return redis.call('echo','foobar') } 0 ] # Test again with EVALSHA set sha [ r script load {#!lua flags=allow-stale,no-writes - return redis.call('info','server') + return redis.call('echo','foobar') } ] - assert_match {*redis_version*} [r evalsha $sha 0] + assert_match {foobar} [r evalsha $sha 0] r replicaof no one r config set replica-serve-stale-data yes