static void cliRefreshPrompt(void) {
if (config.dbnum == 0)
- snprintf(config.prompt,sizeof(config.prompt),"redis> ");
+ snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d> ",
+ config.hostip, config.hostport);
else
- snprintf(config.prompt,sizeof(config.prompt),"redis:%d> ",config.dbnum);
+ snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d[%d]> ",
+ config.hostip, config.hostport, config.dbnum);
}
/*------------------------------------------------------------------------------
return REDIS_OK;
}
-static void cliPrintContextErrorAndExit() {
+static void cliPrintContextError() {
if (context == NULL) return;
fprintf(stderr,"Error: %s\n",context->errstr);
- exit(1);
}
static sds cliFormatReplyTTY(redisReply *r, char *prefix) {
if (context->err == REDIS_ERR_EOF)
return REDIS_ERR;
}
- cliPrintContextErrorAndExit();
+ cliPrintContextError();
+ exit(1);
return REDIS_ERR; /* avoid compiler warning */
}
size_t *argvlen;
int j, output_raw;
- if (context == NULL) {
- printf("Not connected, please use: connect <host> <port>\n");
- return REDIS_OK;
- }
+ if (context == NULL) return REDIS_ERR;
output_raw = 0;
if (!strcasecmp(command,"info") ||
/* If we still cannot send the command,
* print error and abort. */
if (cliSendCommand(argc,argv,1) != REDIS_OK)
- cliPrintContextErrorAndExit();
+ cliPrintContextError();
}
elapsed = mstime()-start_time;
if (elapsed >= 500) {
argc -= firstarg;
argv += firstarg;
- /* Try to connect */
- if (cliConnect(0) != REDIS_OK) exit(1);
-
/* Start interactive mode when no command is provided */
- if (argc == 0) repl();
+ if (argc == 0) {
+ /* Note that in repl mode we don't abort on connection error.
+ * A new attempt will be performed for every command send. */
+ cliConnect(0);
+ repl();
+ }
+
/* Otherwise, we have some arguments to execute */
+ if (cliConnect(0) != REDIS_OK) exit(1);
return noninteractive(argc,convertToSds(argc,argv));
}