From f1b7ece1bc5483ac05cfc5b94e475fb40cd8c6ef Mon Sep 17 00:00:00 2001 From: Sarthak Aggarwal Date: Sun, 5 Jan 2025 14:10:57 -0800 Subject: [PATCH] adding clientCommand as a function for client json Signed-off-by: Sarthak Aggarwal --- src/commands.def | 2 +- src/commands/client.json | 1 + src/networking.c | 30 ++++++------------------------ src/server.h | 1 + 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/commands.def b/src/commands.def index dbdd61e5b2..dd25c2e663 100644 --- a/src/commands.def +++ b/src/commands.def @@ -10922,7 +10922,7 @@ struct COMMAND_STRUCT serverCommandTable[] = { {MAKE_CMD("readwrite","Enables read-write queries for a connection to a Valkey replica node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,READWRITE_History,0,READWRITE_Tips,0,readwriteCommand,1,CMD_FAST|CMD_LOADING|CMD_STALE,ACL_CATEGORY_CONNECTION,READWRITE_Keyspecs,0,NULL,0)}, /* connection */ {MAKE_CMD("auth","Authenticates the connection.","O(N) where N is the number of passwords defined for the user","1.0.0",CMD_DOC_NONE,NULL,NULL,"connection",COMMAND_GROUP_CONNECTION,AUTH_History,1,AUTH_Tips,0,authCommand,-2,CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_FAST|CMD_NO_AUTH|CMD_SENTINEL|CMD_ALLOW_BUSY,ACL_CATEGORY_CONNECTION,AUTH_Keyspecs,0,NULL,2),.args=AUTH_Args}, -{MAKE_CMD("client","A container for client connection commands.","Depends on subcommand.","2.4.0",CMD_DOC_NONE,NULL,NULL,"connection",COMMAND_GROUP_CONNECTION,CLIENT_History,0,CLIENT_Tips,0,NULL,-2,CMD_SENTINEL,0,CLIENT_Keyspecs,0,NULL,0),.subcommands=CLIENT_Subcommands}, +{MAKE_CMD("client","A container for client connection commands.","Depends on subcommand.","2.4.0",CMD_DOC_NONE,NULL,NULL,"connection",COMMAND_GROUP_CONNECTION,CLIENT_History,0,CLIENT_Tips,0,clientCommand,-2,CMD_SENTINEL,0,CLIENT_Keyspecs,0,NULL,0),.subcommands=CLIENT_Subcommands}, {MAKE_CMD("echo","Returns the given string.","O(1)","1.0.0",CMD_DOC_NONE,NULL,NULL,"connection",COMMAND_GROUP_CONNECTION,ECHO_History,0,ECHO_Tips,0,echoCommand,2,CMD_LOADING|CMD_STALE|CMD_FAST,ACL_CATEGORY_CONNECTION,ECHO_Keyspecs,0,NULL,1),.args=ECHO_Args}, {MAKE_CMD("hello","Handshakes with the server.","O(1)","6.0.0",CMD_DOC_NONE,NULL,NULL,"connection",COMMAND_GROUP_CONNECTION,HELLO_History,1,HELLO_Tips,0,helloCommand,-1,CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_FAST|CMD_NO_AUTH|CMD_SENTINEL|CMD_ALLOW_BUSY,ACL_CATEGORY_CONNECTION,HELLO_Keyspecs,0,NULL,1),.args=HELLO_Args}, {MAKE_CMD("ping","Returns the server's liveliness response.","O(1)","1.0.0",CMD_DOC_NONE,NULL,NULL,"connection",COMMAND_GROUP_CONNECTION,PING_History,0,PING_Tips,2,pingCommand,-1,CMD_FAST|CMD_SENTINEL,ACL_CATEGORY_CONNECTION,PING_Keyspecs,0,NULL,1),.args=PING_Args}, diff --git a/src/commands/client.json b/src/commands/client.json index b50996128e..116fb4d4a2 100644 --- a/src/commands/client.json +++ b/src/commands/client.json @@ -4,6 +4,7 @@ "complexity": "Depends on subcommand.", "group": "connection", "since": "2.4.0", + "function": "clientCommand", "arity": -2, "command_flags": [ "SENTINEL" diff --git a/src/networking.c b/src/networking.c index 56ae517601..524b47b572 100644 --- a/src/networking.c +++ b/src/networking.c @@ -74,27 +74,6 @@ static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter) static int clientMatchesFilter(client *client, clientFilter client_filter); static sds getAllFilteredClientsInfoString(clientFilter *client_filter, int hide_user_data); -#define IS_CLIENT_SUBCOMMAND(cmd) \ - (cmd == clientCommandHelp || \ - cmd == clientCommandID || \ - cmd == clientCommandInfo || \ - cmd == clientCommandList || \ - cmd == clientCommandReply || \ - cmd == clientCommandNoEvict || \ - cmd == clientCommandKill || \ - cmd == clientCommandUnblock || \ - cmd == clientCommandSetName || \ - cmd == clientCommandGetName || \ - cmd == clientCommandUnpause || \ - cmd == clientCommandPause || \ - cmd == clientCommandTracking || \ - cmd == clientCommandCaching || \ - cmd == clientCommandGetredir || \ - cmd == clientCommandTrackingInfo || \ - cmd == clientCommandNoTouch || \ - cmd == clientCommandCapa || \ - cmd == clientCommandImportSource) - int ProcessingEventsWhileBlocked = 0; /* See processEventsWhileBlocked(). */ __thread sds thread_shared_qb = NULL; @@ -2599,6 +2578,7 @@ int handleClientsWithPendingWrites(void) { /* resetClient prepare the client to process the next command */ void resetClient(client *c) { serverCommandProc *prevcmd = c->cmd ? c->cmd->proc : NULL; + serverCommandProc *prevParentCmd = c->cmd && c->cmd->parent ? c->cmd->parent->proc : NULL; freeClientArgv(c); freeClientOriginalArgv(c); @@ -2628,9 +2608,7 @@ void resetClient(client *c) { /* We do the same for the CACHING command as well. It also affects * the next command or transaction executed, in a way very similar * to ASKING. */ - if (!c->flag.multi && !IS_CLIENT_SUBCOMMAND(prevcmd)) { - c->flag.tracking_caching = 0; - } + if (!c->flag.multi && prevParentCmd != clientCommand) c->flag.tracking_caching = 0; /* Remove the CLIENT_REPLY_SKIP flag if any so that the reply * to the next command will be sent, but set the flag if the command @@ -4274,6 +4252,10 @@ void clientCommandImportSource(client *c) { } } +void clientCommand(client *c) { + addReplySubcommandSyntaxError(c); +} + /* HELLO [ [AUTH ] [SETNAME ] ] */ void helloCommand(client *c) { long long ver = 0; diff --git a/src/server.h b/src/server.h index 7babffcd9a..1f5e5f0c78 100644 --- a/src/server.h +++ b/src/server.h @@ -3757,6 +3757,7 @@ int verifyDumpPayload(unsigned char *p, size_t len, uint16_t *rdbver_ptr); void dumpCommand(client *c); void objectCommand(client *c); void memoryCommand(client *c); +void clientCommand(client *c); void clientCommandHelp(client *c); void clientCommandID(client *c); void clientCommandInfo(client *c);