redis-cli history saved across sessions

This commit is contained in:
antirez
2010-07-07 18:44:53 +02:00
parent 185cabda45
commit 99628c1af8
3 changed files with 54 additions and 7 deletions

View File

@ -61,6 +61,7 @@ static struct config {
int pubsub_mode;
int raw_output;
char *auth;
char *historyfile;
} config;
static int cliReadReply(int fd);
@ -439,6 +440,7 @@ static void repl() {
if (line[0] != '\0') {
argv = splitArguments(line,&argc);
linenoiseHistoryAdd(line);
if (config.historyfile) linenoiseHistorySave(config.historyfile);
if (argc > 0) {
if (strcasecmp(argv[0],"quit") == 0 ||
strcasecmp(argv[0],"exit") == 0)
@ -472,6 +474,13 @@ int main(int argc, char **argv) {
config.pubsub_mode = 0;
config.raw_output = 0;
config.auth = NULL;
config.historyfile = NULL;
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;