Skip to content

Commit

Permalink
adding clientCommand as a function for client json
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Jan 5, 2025
1 parent 4eb8ddb commit f1b7ece
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
1 change: 1 addition & 0 deletions src/commands/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"complexity": "Depends on subcommand.",
"group": "connection",
"since": "2.4.0",
"function": "clientCommand",
"arity": -2,
"command_flags": [
"SENTINEL"
Expand Down
30 changes: 6 additions & 24 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4274,6 +4252,10 @@ void clientCommandImportSource(client *c) {
}
}

void clientCommand(client *c) {
addReplySubcommandSyntaxError(c);
}

/* HELLO [<protocol-version> [AUTH <user> <password>] [SETNAME <name>] ] */
void helloCommand(client *c) {
long long ver = 0;
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f1b7ece

Please sign in to comment.