Ejemplo n.º 1
0
static void repl() {
    int size = 4096, max = size >> 1, argc;
    char buffer[size];
    char *line = buffer;
    char **ap, *args[max];

    if (config.auth != NULL) {
        char *authargv[2];

        authargv[0] = "AUTH";
        authargv[1] = config.auth;
        cliSendCommand(2, convertToSds(2, authargv));
    }

    while (prompt(line, size)) {
        argc = 0;

        for (ap = args; (*ap = strsep(&line, " \t")) != NULL;) {
            if (**ap != '\0') {
                if (argc >= max) break;
                if (strcasecmp(*ap,"quit") == 0 || strcasecmp(*ap,"exit") == 0)
                    exit(0);
                ap++;
                argc++;
            }
        }

        config.repeat = 1;
        cliSendCommand(argc, convertToSds(argc, args));
        line = buffer;
    }

    exit(0);
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
    int firstarg;
    char **argvcopy;
    struct redisCommand *rc;

    config.hostip = "127.0.0.1";
    config.hostport = 6379;
    config.repeat = 1;
    config.dbnum = 0;
    config.interactive = 0;
    config.auth = NULL;

    firstarg = parseOptions(argc,argv);
    argc -= firstarg;
    argv += firstarg;

    if (argc == 0 || config.interactive == 1) repl();

    argvcopy = convertToSds(argc, argv);

    /* Read the last argument from stdandard input if needed */
    if ((rc = lookupCommand(argv[0])) != NULL) {
      if (rc->arity > 0 && argc == rc->arity-1) {
        sds lastarg = readArgFromStdin();
        argvcopy[argc] = lastarg;
        argc++;
      }
    }

    return cliSendCommand(argc, argvcopy);
}
Ejemplo n.º 3
0
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));
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
    int firstarg;
    char **argvcopy;
    struct redisCommand *rc;

    config.hostip = "127.0.0.1";
    config.hostport = 6379;
    config.repeat = 1;
    config.dbnum = 0;
    config.shutdown = 0;
    config.interactive = 0;
    config.monitor_mode = 0;
    config.pubsub_mode = 0;
    config.raw_output = 0;
    config.auth = NULL;

    firstarg = parseOptions(argc,argv);
    argc -= firstarg;
    argv += firstarg;

    if (config.auth != NULL) {
        char *authargv[2];

        authargv[0] = "AUTH";
        authargv[1] = config.auth;
        cliSendCommand(2, convertToSds(2, authargv), 1);
    }

    if (argc == 0 || config.interactive == 1) repl();

    argvcopy = convertToSds(argc, argv);

    /* Read the last argument from stdandard input if needed */
    if ((rc = lookupCommand(argv[0])) != NULL) {
      if (rc->arity > 0 && argc == rc->arity-1) {
        sds lastarg = readArgFromStdin();
        argvcopy[argc] = lastarg;
        argc++;
      }
    }

    return cliSendCommand(argc, argvcopy, config.repeat);
}
Ejemplo n.º 5
0
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));
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {
    int firstarg;
    char **argvcopy;

    config.hostip = "127.0.0.1";
    config.hostport = 6379;
    config.repeat = 1;
    config.dbnum = 0;
    config.argn_from_stdin = 0;
    config.shutdown = 0;
    config.interactive = 0;
    config.monitor_mode = 0;
    config.pubsub_mode = 0;
    config.raw_output = 0;
    config.auth = NULL;

    firstarg = parseOptions(argc,argv);
    argc -= firstarg;
    argv += firstarg;

    if (config.auth != NULL) {
        char *authargv[2];

        authargv[0] = "AUTH";
        authargv[1] = config.auth;
        cliSendCommand(2, convertToSds(2, authargv), 1);
    }

    if (argc == 0 || config.interactive == 1) repl();

    argvcopy = convertToSds(argc+1, argv);
    if (config.argn_from_stdin) {
        sds lastarg = readArgFromStdin();
        argvcopy[argc] = lastarg;
        argc++;
    }
    return cliSendCommand(argc, argvcopy, config.repeat);
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
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));
}
Ejemplo n.º 9
0
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));
    }
}