mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 08:08:53 -05:00
redis-cli prompt: show transaction state, and fix db number on aborted EXEC (#6728)
This commit is contained in:
parent
ab60dcf564
commit
f74c32cad2
@ -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,12 +1402,31 @@ 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){
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user