int main(int argc, char **argv) { int firstarg; config.hostip = sdsnew("127.0.0.1"); config.hostport = 6379; config.hostsocket = NULL; config.repeat = 1; config.interval = 0; config.dbnum = 0; config.interactive = 0; config.shutdown = 0; config.monitor_mode = 0; config.pubsub_mode = 0; config.latency_mode = 0; config.stdinarg = 0; config.auth = NULL; config.raw_output = !isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL); config.mb_delim = sdsnew("\n"); cliInitHelp(); #ifdef _WIN32 _fmode = _O_BINARY; _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); _setmode(_fileno(stderr), _O_BINARY); if (!w32initWinSock()) { printf("Winsock init error %d", WSAGetLastError()); exit(1); }; atexit((void(*)(void)) WSACleanup); #endif firstarg = parseOptions(argc,argv); argc -= firstarg; argv += firstarg; /* Start in latency mode if appropriate */ if (config.latency_mode) { cliConnect(0); latencyMode(); } /* Start interactive mode when no command is provided */ 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)); }
int main(int argc, char **argv) { int firstarg; config.hostip = "127.0.0.1"; config.hostport = 6379; config.repeat = 1; config.dbnum = 0; config.interactive = 0; config.shutdown = 0; config.monitor_mode = 0; config.pubsub_mode = 0; config.raw_output = 0; config.stdinarg = 0; config.auth = NULL; config.historyfile = NULL; config.tty = isatty(fileno(stdout)) || (getenv("FAKETTY") != NULL); config.mb_sep = '\n'; if (getenv("HOME") != NULL) { config.historyfile = malloc(256); snprintf(config.historyfile,256,"%s/.rediscli_history",getenv("HOME")); linenoiseHistoryLoad(config.historyfile); } firstarg = parseOptions(argc,argv); argc -= firstarg; argv += firstarg; if (config.auth != NULL) { char *authargv[2]; int dbnum = config.dbnum; /* We need to save the real configured database number and set it to * zero here, otherwise cliSendCommand() will try to perform the * SELECT command before the authentication, and it will fail. */ config.dbnum = 0; authargv[0] = "AUTH"; authargv[1] = config.auth; cliSendCommand(2, convertToSds(2, authargv), 1); config.dbnum = dbnum; /* restore the right DB number */ } /* Start interactive mode when no command is provided */ if (argc == 0) repl(); /* Otherwise, we have some arguments to execute */ return noninteractive(argc,convertToSds(argc,argv)); }
int main(int argc, char **argv) { int firstarg; config.filename = sdsnew("redislite.db"); config.repeat = 1; config.interactive = 0; config.stdinarg = 0; config.historyfile = NULL; config.raw_output = !isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL); config.mb_delim = sdsnew("\n"); cliInitHelp(); if (getenv("HOME") != NULL) { config.historyfile = malloc(256); snprintf(config.historyfile, 256, "%s/.redislitecli_history", getenv("HOME")); linenoiseHistoryLoad(config.historyfile); } firstarg = parseOptions(argc, argv); argc -= firstarg; argv += firstarg; /* Try to connect */ if (cliConnect(0) != REDISLITE_OK) { exit(1); } /* Start interactive mode when no command is provided */ if (argc == 0) { repl(); } /* Otherwise, we have some arguments to execute */ char **converted = convertToSds(argc, argv); int ret = noninteractive(argc, converted); cliCleanHelp(); // NOTE: not free-ing converted since it may have changed inside noninteractive sdsfree(config.filename); sdsfree(config.mb_delim); redislite_close_database(db); return ret; }
int main(int argc, char **argv) { int firstarg; config.hostip = sdsnew("127.0.0.1"); config.hostport = 6379; config.hostsocket = NULL; config.repeat = 1; config.dbnum = 0; config.interactive = 0; config.shutdown = 0; config.monitor_mode = 0; config.pubsub_mode = 0; config.stdinarg = 0; config.auth = NULL; config.historyfile = NULL; config.raw_output = !isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL); config.mb_delim = sdsnew("\n"); cliInitHelp(); if (getenv("HOME") != NULL) { config.historyfile = malloc(256); snprintf(config.historyfile,256,"%s/.rediscli_history",getenv("HOME")); linenoiseHistoryLoad(config.historyfile); } firstarg = parseOptions(argc,argv); 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(); /* Otherwise, we have some arguments to execute */ return noninteractive(argc,convertToSds(argc,argv)); }
int main(int argc, char **argv) { int firstarg; config.hostip = sdsnew("127.0.0.1"); config.hostport = 6379; config.hostsocket = NULL; config.repeat = 1; config.interval = 0; config.dbnum = 0; config.interactive = 0; config.shutdown = 0; config.monitor_mode = 0; config.pubsub_mode = 0; config.latency_mode = 0; config.cluster_mode = 0; config.slave_mode = 0; config.pipe_mode = 0; config.bigkeys = 0; config.stdinarg = 0; config.auth = NULL; config.eval = NULL; if (!isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL)) config.output = OUTPUT_RAW; else config.output = OUTPUT_STANDARD; config.mb_delim = sdsnew("\n"); cliInitHelp(); firstarg = parseOptions(argc,argv); argc -= firstarg; argv += firstarg; /* Latency mode */ if (config.latency_mode) { cliConnect(0); latencyMode(); } /* Slave mode */ if (config.slave_mode) { cliConnect(0); slaveMode(); } /* Pipe mode */ if (config.pipe_mode) { if (cliConnect(0) == REDIS_ERR) exit(1); pipeMode(); } /* Find big keys */ if (config.bigkeys) { cliConnect(0); findBigKeys(); } /* Start interactive mode when no command is provided */ if (argc == 0 && !config.eval) { /* 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); if (config.eval) { return evalMode(argc,argv); } else { return noninteractive(argc,convertToSds(argc,argv)); } }