summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-09-23 17:55:05 +0200
committerantirez <antirez@gmail.com>2019-09-23 17:55:05 +0200
commitcc108057ffda25a5421e2acc23dc63fe3c7b13d8 (patch)
treed328210a44d6fd498fafd140c89f2cf858693bb0
parent8ea185ea30853cd067a44d18895029be76591edb (diff)
downloadredis-cc108057ffda25a5421e2acc23dc63fe3c7b13d8.tar.gz
redis-cli: ability to start a session in RESP3 mode.
-rw-r--r--src/redis-cli.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 38a0b0b7f..47bd11a8a 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -230,6 +230,7 @@ static struct config {
int verbose;
clusterManagerCommand cluster_manager_command;
int no_auth_warning;
+ int resp3;
} config;
/* User preferences. */
@@ -751,6 +752,21 @@ static int cliSelect(void) {
return REDIS_ERR;
}
+/* Select RESP3 mode if redis-cli was started with the -3 option. */
+static int cliSwitchProto(void) {
+ redisReply *reply;
+ if (config.resp3 == 0) return REDIS_OK;
+
+ reply = redisCommand(context,"HELLO 3");
+ if (reply != NULL) {
+ int result = REDIS_OK;
+ if (reply->type == REDIS_REPLY_ERROR) result = REDIS_ERR;
+ freeReplyObject(reply);
+ return result;
+ }
+ return REDIS_ERR;
+}
+
/* Connect to the server. It is possible to pass certain flags to the function:
* CC_FORCE: The connection is performed even if there is already
* a connected socket.
@@ -788,11 +804,13 @@ static int cliConnect(int flags) {
* errors. */
anetKeepAlive(NULL, context->fd, REDIS_CLI_KEEPALIVE_INTERVAL);
- /* Do AUTH and select the right DB. */
+ /* Do AUTH, select the right DB, switch to RESP3 if needed. */
if (cliAuth() != REDIS_OK)
return REDIS_ERR;
if (cliSelect() != REDIS_OK)
return REDIS_ERR;
+ if (cliSwitchProto() != REDIS_OK)
+ return REDIS_ERR;
}
return REDIS_OK;
}
@@ -1449,6 +1467,8 @@ static int parseOptions(int argc, char **argv) {
printf("redis-cli %s\n", version);
sdsfree(version);
exit(0);
+ } else if (!strcmp(argv[i],"-3")) {
+ config.resp3 = 1;
} else if (CLUSTER_MANAGER_MODE() && argv[i][0] != '-') {
if (config.cluster_manager_command.argc == 0) {
int j = i + 1;
@@ -1529,6 +1549,7 @@ static void usage(void) {
" -i <interval> When -r is used, waits <interval> seconds per command.\n"
" It is possible to specify sub-second times like -i 0.1.\n"
" -n <db> Database number.\n"
+" -3 Start session in RESP3 protocol mode.\n"
" -x Read last argument from STDIN.\n"
" -d <delimiter> Multi-bulk delimiter in for raw formatting (default: \\n).\n"
" -c Enable cluster mode (follow -ASK and -MOVED redirections).\n"
@@ -1543,7 +1564,9 @@ static void usage(void) {
" --csv is specified, or if you redirect the output to a non\n"
" TTY, it samples the latency for 1 second (you can use\n"
" -i to change the interval), then produces a single output\n"
-" and exits.\n"
+" and exits.\n",version);
+
+ fprintf(stderr,
" --latency-history Like --latency but tracking latency changes over time.\n"
" Default time interval is 15 sec. Change it using -i.\n"
" --latency-dist Shows latency as a spectrum, requires xterm 256 colors.\n"
@@ -1578,7 +1601,7 @@ static void usage(void) {
" --help Output this help and exit.\n"
" --version Output version and exit.\n"
"\n",
- version, REDIS_CLI_DEFAULT_PIPE_TIMEOUT);
+ REDIS_CLI_DEFAULT_PIPE_TIMEOUT);
/* Using another fprintf call to avoid -Woverlength-strings compile warning */
fprintf(stderr,
"Cluster Manager Commands:\n"