Skip to content

Loading…

fixed prompt in redis cli when connecting to a socket; fixes issue #306 #314

Open
wants to merge 2 commits into from

3 participants

@tchajed

No description provided.

@pietern

A couple of remarks. This function:

  • does not follow indentation convention.
  • creates an sds which it not free'd.
  • contains an unnecessary comment.

Can you address these issues? Thanks.

@tchajed tchajed fixed style issues with cliRefreshPrompt and expanded memory for
config.prompt to account for possibly long socket pathnames
886fed4
@antirez
Owner

The patch still does not seem ok to me, since when the socket is selected no [db_num] is added to the prompt. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 25, 2012
  1. @tchajed
  2. @tchajed

    fixed style issues with cliRefreshPrompt and expanded memory for

    tchajed committed
    config.prompt to account for possibly long socket pathnames
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/redis-cli.c
View
20 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,18 @@ 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);
- else
- snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d[%d]> ",
- config.hostip, config.hostport, config.dbnum);
+ sds prompt = sdsnew("redis ");
+ if (config.hostsocket != NULL) {
+ prompt = sdscat(prompt, config.hostsocket);
+ } else {
+ prompt = sdscatprintf(prompt, "%s:%d", config.hostip, config.hostport);
+ if (config.dbnum > 0) {
+ prompt = sdscatprintf(prompt, "[%d]", config.dbnum);
+ }
+ }
+ prompt = sdscat(prompt, "> ");
+ strncpy(config.prompt, prompt, sizeof(config.prompt));
+ sdsfree(prompt);
}
/*------------------------------------------------------------------------------
Something went wrong with that request. Please try again.