summaryrefslogtreecommitdiff
path: root/src/networking.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-12-04 12:46:16 +0100
committerantirez <antirez@gmail.com>2019-01-09 17:00:29 +0100
commit4f0860cbfd84bb28c895eae525a7168014dc37f8 (patch)
tree99d6696d47c8609f75f6dd7b6e73cdc85de94ea2 /src/networking.c
parente5fdd6b6bfa769d83a49643bf58cbe681ed2dfe2 (diff)
downloadredis-4f0860cbfd84bb28c895eae525a7168014dc37f8.tar.gz
RESP3: initial implementation of the HELLO command.
Diffstat (limited to 'src/networking.c')
-rw-r--r--src/networking.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/networking.c b/src/networking.c
index 8be226292..5e442e289 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -1998,6 +1998,54 @@ NULL
}
}
+/* HELLO <protocol-version> [AUTH <user> <password>] */
+void helloCommand(client *c) {
+ long long ver;
+
+ if (getLongLongFromObject(c->argv[1],&ver) != C_OK ||
+ ver < 2 || ver > 3)
+ {
+ addReplyError(c,"-NOPROTO unsupported protocol version");
+ return;
+ }
+
+ /* Switching to protocol v2 is not allowed. But we send a specific
+ * error message in this case. */
+ if (ver == 2) {
+ addReplyError(c,"Switching to RESP version 2 is not allowed.");
+ return;
+ }
+
+ /* Let's switch to RESP3 mode. */
+ c->resp = 3;
+ addReplyMapLen(c,7);
+
+ addReplyBulkCString(c,"server");
+ addReplyBulkCString(c,"redis");
+
+ addReplyBulkCString(c,"version");
+ addReplyBulkCString(c,REDIS_VERSION);
+
+ addReplyBulkCString(c,"proto");
+ addReplyLongLong(c,3);
+
+ addReplyBulkCString(c,"id");
+ addReplyLongLong(c,c->id);
+
+ addReplyBulkCString(c,"mode");
+ if (server.sentinel_mode) addReplyBulkCString(c,"sentinel");
+ if (server.cluster_enabled) addReplyBulkCString(c,"cluster");
+ else addReplyBulkCString(c,"standalone");
+
+ if (!server.sentinel_mode) {
+ addReplyBulkCString(c,"role");
+ addReplyBulkCString(c,server.masterhost ? "replica" : "master");
+ }
+
+ addReplyBulkCString(c,"modules");
+ addReplyLoadedModules(c);
+}
+
/* This callback is bound to POST and "Host:" command names. Those are not
* really commands, but are used in security attacks in order to talk to
* Redis instances via HTTP, with a technique called "cross protocol scripting"