Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
f74c32ca
Unverified
Commit
f74c32ca
authored
Dec 13, 2020
by
Wen Hui
Committed by
GitHub
Dec 13, 2020
Browse files
redis-cli prompt: show transaction state, and fix db number on aborted EXEC (#6728)
parent
ab60dcf5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
f74c32ca
...
...
@@ -252,6 +252,8 @@ static struct config {
clusterManagerCommand cluster_manager_command;
int no_auth_warning;
int resp3;
int in_multi;
int pre_multi_dbnum;
} config;
/* User preferences. */
...
...
@@ -307,6 +309,10 @@ static void cliRefreshPrompt(void) {
if (config.dbnum != 0)
prompt = sdscatfmt(prompt,"[%i]",config.dbnum);
/* Add TX if in transaction state*/
if (config.in_multi)
prompt = sdscatlen(prompt,"(TX)",4);
/* Copy the prompt in the static buffer. */
prompt = sdscatlen(prompt,"> ",2);
snprintf(config.prompt,sizeof(config.prompt),"%s",prompt);
...
...
@@ -1396,13 +1402,32 @@ static int cliSendCommand(int argc, char **argv, long repeat) {
return REDIS_ERR;
} else {
/* Store database number when SELECT was successfully executed. */
if (!strcasecmp(command,"select") && argc == 2 && config.last_cmd_type != REDIS_REPLY_ERROR) {
if (!strcasecmp(command,"select") && argc == 2 &&
config.last_cmd_type != REDIS_REPLY_ERROR)
{
config.dbnum = atoi(argv[1]);
cliRefreshPrompt();
} else if (!strcasecmp(command,"auth") && (argc == 2 || argc == 3))
{
} else if (!strcasecmp(command,"auth") && (argc == 2 || argc == 3)) {
cliSelect();
}
} else if (!strcasecmp(command,"multi") && argc == 1 &&
config.last_cmd_type != REDIS_REPLY_ERROR)
{
config.in_multi = 1;
config.pre_multi_dbnum = config.dbnum;
cliRefreshPrompt();
} else if (!strcasecmp(command,"exec") && argc == 1 && config.in_multi) {
config.in_multi = 0;
if (config.last_cmd_type == REDIS_REPLY_ERROR) {
config.dbnum = config.pre_multi_dbnum;
}
cliRefreshPrompt();
} else if (!strcasecmp(command,"discard") && argc == 1 &&
config.last_cmd_type != REDIS_REPLY_ERROR)
{
config.in_multi = 0;
config.dbnum = config.pre_multi_dbnum;
cliRefreshPrompt();
}
}
if (config.cluster_reissue_command){
/* If we need to reissue the command, break to prevent a
...
...
@@ -8139,6 +8164,7 @@ int main(int argc, char **argv) {
config.verbose = 0;
config.set_errcode = 0;
config.no_auth_warning = 0;
config.in_multi = 0;
config.cluster_manager_command.name = NULL;
config.cluster_manager_command.argc = 0;
config.cluster_manager_command.argv = NULL;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment