X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/e2f313899bf985fe691428af8466d10e3e67a6fd..ad08d059d01ecae5e8c0eae3f31a202896bec4dc:/src/redis-cli.c diff --git a/src/redis-cli.c b/src/redis-cli.c index 3f60a132..827e4061 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -68,7 +68,7 @@ static struct config { char *auth; int raw_output; /* output mode per command */ sds mb_delim; - char prompt[32]; + char prompt[128]; char *eval; } config; @@ -91,12 +91,19 @@ static long long mstime(void) { } static void cliRefreshPrompt(void) { - if (config.dbnum == 0) - snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d> ", - config.hostip, config.hostport); + int len; + + if (config.hostsocket != NULL) + len = snprintf(config.prompt,sizeof(config.prompt),"redis %s", + config.hostsocket); else - snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d[%d]> ", - config.hostip, config.hostport, config.dbnum); + len = snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d", + config.hostip, config.hostport); + /* Add [dbnum] if needed */ + if (config.dbnum != 0) + len += snprintf(config.prompt+len,sizeof(config.prompt)-len,"[%d]", + config.dbnum); + snprintf(config.prompt+len,sizeof(config.prompt)-len,"> "); } /*------------------------------------------------------------------------------ @@ -501,6 +508,11 @@ static int cliSendCommand(int argc, char **argv, int repeat) { size_t *argvlen; int j, output_raw; + if (!strcasecmp(command,"help") || !strcasecmp(command,"?")) { + cliOutputHelp(--argc, ++argv); + return REDIS_OK; + } + if (context == NULL) return REDIS_ERR; output_raw = 0; @@ -515,10 +527,6 @@ static int cliSendCommand(int argc, char **argv, int repeat) { output_raw = 1; } - if (!strcasecmp(command,"help") || !strcasecmp(command,"?")) { - cliOutputHelp(--argc, ++argv); - return REDIS_OK; - } if (!strcasecmp(command,"shutdown")) config.shutdown = 1; if (!strcasecmp(command,"monitor")) config.monitor_mode = 1; if (!strcasecmp(command,"subscribe") ||