]> git.saurik.com Git - redis.git/blobdiff - src/redis-cli.c
use the function deprecated attribute if compiling with GCC to get warnings for mallo...
[redis.git] / src / redis-cli.c
index 1d00fb87398446ff51419165eaaabe3c9de58bdf..dac8286251b983d233729885d05f7dc866bd9598 100644 (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;