summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-06-20 10:21:38 +0200
committerantirez <antirez@gmail.com>2013-06-20 10:24:43 +0200
commit252f0b65562c622fedf694753f67a07909215741 (patch)
tree3ea304c3bd2f1432f51335ce8d057a98a6c3bba7
parentee92c043fc0bda824f98e62959c2ee26eec6024e (diff)
downloadredis-252f0b65562c622fedf694753f67a07909215741.tar.gz
Sentinel: parse new INFO replication output correctly.
Sentinel was not able to detect slaves when connected to a very recent version of Redis master since a previos non-backward compatible change to INFO broken the parsing of the slaves ip:port INFO output. This fixes issue #1164
-rw-r--r--src/sentinel.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/sentinel.c b/src/sentinel.c
index a4db9408e..ed0978694 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -1397,20 +1397,33 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
}
}
- /* slave0:<ip>,<port>,<state> */
+ /* old versions: slave0:<ip>,<port>,<state>
+ * new versions: slave0:ip=127.0.0.1,port=9999,... */
if ((ri->flags & SRI_MASTER) &&
sdslen(l) >= 7 &&
!memcmp(l,"slave",5) && isdigit(l[5]))
{
char *ip, *port, *end;
- ip = strchr(l,':'); if (!ip) continue;
- ip++; /* Now ip points to start of ip address. */
- port = strchr(ip,','); if (!port) continue;
- *port = '\0'; /* nul term for easy access. */
- port++; /* Now port points to start of port number. */
- end = strchr(port,','); if (!end) continue;
- *end = '\0'; /* nul term for easy access. */
+ if (strstr(l,"ip=") == NULL) {
+ /* Old format. */
+ ip = strchr(l,':'); if (!ip) continue;
+ ip++; /* Now ip points to start of ip address. */
+ port = strchr(ip,','); if (!port) continue;
+ *port = '\0'; /* nul term for easy access. */
+ port++; /* Now port points to start of port number. */
+ end = strchr(port,','); if (!end) continue;
+ *end = '\0'; /* nul term for easy access. */
+ } else {
+ /* New format. */
+ ip = strstr(l,"ip="); if (!ip) continue;
+ ip += 3; /* Now ip points to start of ip address. */
+ port = strstr(l,"port="); if (!port) continue;
+ port += 5; /* Now port points to start of port number. */
+ /* Nul term both fields for easy access. */
+ end = strchr(ip,','); if (end) *end = '\0';
+ end = strchr(port,','); if (end) *end = '\0';
+ }
/* Check if we already have this slave into our table,
* otherwise add it. */