- if (fd == ANET_ERR || force) {
- if (force) close(fd);
- if (config.hostsocket == NULL) {
- fd = anetTcpConnect(err,config.hostip,config.hostport);
- } else {
- fd = anetUnixConnect(err,config.hostsocket);
- }
- if (fd == ANET_ERR) {
- fprintf(stderr,"Could not connect to Redis at ");
- if (config.hostsocket == NULL)
- fprintf(stderr,"%s:%d: %s",config.hostip,config.hostport,err);
- else
- fprintf(stderr,"%s: %s",config.hostsocket,err);
- return -1;
- }
- anetTcpNoDelay(NULL,fd);
+static long long mstime(void) {
+ struct timeval tv;
+ long long mst;
+
+ gettimeofday(&tv, NULL);
+ mst = ((long)tv.tv_sec)*1000;
+ mst += tv.tv_usec/1000;
+ return mst;
+}
+
+static void cliRefreshPrompt(void) {
+ if (config.dbnum == 0)
+ snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d> ",
+ config.hostip, config.hostport);
+ else
+ snprintf(config.prompt,sizeof(config.prompt),"redis %s:%d[%d]> ",
+ config.hostip, config.hostport, config.dbnum);
+}
+
+/*------------------------------------------------------------------------------
+ * Help functions
+ *--------------------------------------------------------------------------- */
+
+#define CLI_HELP_COMMAND 1
+#define CLI_HELP_GROUP 2
+
+typedef struct {
+ int type;
+ int argc;
+ sds *argv;
+ sds full;
+
+ /* Only used for help on commands */
+ struct commandHelp *org;
+} helpEntry;
+
+static helpEntry *helpEntries;
+static int helpEntriesLen;
+
+static sds cliVersion() {
+ sds version;
+ version = sdscatprintf(sdsempty(), "%s", REDIS_VERSION);
+
+ /* Add git commit and working tree status when available */
+ if (strtoll(redisGitSHA1(),NULL,16)) {
+ version = sdscatprintf(version, " (git:%s", redisGitSHA1());
+ if (strtoll(redisGitDirty(),NULL,10))
+ version = sdscatprintf(version, "-dirty");
+ version = sdscat(version, ")");