static int cliReadReply(int output_raw_strings) { redisReply *reply; sds out; if (redisGetReply(context,(void**)&reply) != REDIS_OK) { if (config.shutdown) return REDIS_OK; if (config.interactive) { /* Filter cases where we should reconnect */ if (context->err == REDIS_ERR_IO && errno == ECONNRESET) return REDIS_ERR; if (context->err == REDIS_ERR_EOF) return REDIS_ERR; } cliPrintContextErrorAndExit(); return REDIS_ERR; /* avoid compiler warning */ } if (output_raw_strings) { out = cliFormatReplyRaw(reply); } else { if (config.raw_output) { out = cliFormatReplyRaw(reply); out = sdscat(out,"\n"); } else { out = cliFormatReplyTTY(reply,""); } } fwrite(out,sdslen(out),1,stdout); sdsfree(out); freeReplyObject(reply); return REDIS_OK; }
static int cliReadReply(redislite_reply *reply, int output_raw_strings) { sds out; if (reply == NULL) { cliPrintContextErrorAndExit(); return REDISLITE_ERR; /* avoid compiler warning */ } if (output_raw_strings) { out = cliFormatReplyRaw(reply); } else { if (config.raw_output) { out = cliFormatReplyRaw(reply); out = sdscat(out, "\n"); } else { out = cliFormatReplyTTY(reply, ""); } } fwrite(out, sdslen(out), 1, stdout); sdsfree(out); redislite_free_reply(reply); return REDISLITE_OK; }
static void repl() { int argc, j; char *line; sds *argv; config.interactive = 1; linenoiseSetCompletionCallback(completionCallback); while((line = linenoise(db ? "redislite> " : "not connected> ")) != NULL) { if (line[0] != '\0') { argv = sdssplitargs(line, &argc); linenoiseHistoryAdd(line); if (config.historyfile) { linenoiseHistorySave(config.historyfile); } if (argv == NULL) { printf("Invalid argument(s)\n"); continue; } else if (argc > 0) { if (strcasecmp(argv[0], "quit") == 0 || strcasecmp(argv[0], "exit") == 0) { exit(0); } else if (argc == 1 && !strcasecmp(argv[0], "clear")) { linenoiseClearScreen(); } else { long long start_time = mstime(), elapsed; if (cliSendCommand(argc, argv, 1) != REDISLITE_OK) { cliConnect(1); /* If we still cannot send the command, * print error and abort. */ if (cliSendCommand(argc, argv, 1) != REDISLITE_OK) { cliPrintContextErrorAndExit(); } } elapsed = mstime() - start_time; if (elapsed >= 500) { printf("(%.2fs)\n", (double)elapsed / 1000); } } } /* Free the argument vector */ for (j = 0; j < argc; j++) { sdsfree(argv[j]); } redislite_free(argv); } /* linenoise() returns malloc-ed lines like readline() */ free(line); } exit(0); }