-/* Connect to the client. If force is not zero the connection is performed
- * even if there is already a connected socket. */
-static int cliConnect(int force) {
- char err[ANET_ERR_LEN];
- static int fd = ANET_ERR;
-
- if (fd == ANET_ERR || force) {
- if (force) close(fd);
- fd = anetTcpConnect(err,config.hostip,config.hostport);
- if (fd == ANET_ERR) {
- fprintf(stderr, "Could not connect to Redis at %s:%d: %s", config.hostip, config.hostport, err);
- return -1;
- }
- anetTcpNoDelay(NULL,fd);
+/*------------------------------------------------------------------------------
+ * Utility functions
+ *--------------------------------------------------------------------------- */
+
+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, ")");