Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add REDISCLI_HISTFILE

  • Loading branch information...
commit f0b1979b50b4d49bdb8af3c690496802ca498a22 1 parent f1481d4
@openbaas openbaas authored
Showing with 27 additions and 4 deletions.
  1. +27 −4 src/redis-cli.c
View
31 src/redis-cli.c
@@ -753,6 +753,30 @@ static char **convertToSds(int count, char** args) {
return sds;
}
+#define REDISCLI_HISTFILE "REDISCLI_HISTFILE"
+#define DEFAULT_REDISCLI_HISTFILE ".rediscli_history"
+
+static sds getHistoryPath() {
+ char *path = NULL;
+ sds historyPath = NULL;
+
+ path = getenv(REDISCLI_HISTFILE);
+ if (path != NULL && *path != '\0') {
+ if (!strcmp("/dev/null", path)) {
+ return NULL;
+ }
+
+ historyPath = sdscatprintf(sdsempty(), "%s", path);
+ } else {
+ char *home = getenv("HOME");
+ if (home != NULL && *home != '\0') {
+ historyPath = sdscatprintf(sdsempty(), "%s/%s", home, DEFAULT_REDISCLI_HISTFILE);
+ }
+ }
+
+ return historyPath;
+}
+
#define LINE_BUFLEN 4096
static void repl() {
sds historyfile = NULL;
@@ -766,10 +790,9 @@ static void repl() {
/* Only use history when stdin is a tty. */
if (isatty(fileno(stdin))) {
- history = 1;
-
- if (getenv("HOME") != NULL) {
- historyfile = sdscatprintf(sdsempty(),"%s/.rediscli_history",getenv("HOME"));
+ historyfile = getHistoryPath();
+ if (historyfile != NULL) {
+ history = 1;
linenoiseHistoryLoad(historyfile);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.