From aeedfae544199ff9089bfc862bdfafe7d654dcde Mon Sep 17 00:00:00 2001 From: fortrue Date: Sat, 2 Sep 2017 12:32:19 +0800 Subject: [PATCH] support redis4.0 command "cluster nodes" address parse --- src/ClusterServerPool.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ClusterServerPool.cpp b/src/ClusterServerPool.cpp index 7927c7d..0dd5a5e 100644 --- a/src/ClusterServerPool.cpp +++ b/src/ClusterServerPool.cpp @@ -109,8 +109,18 @@ void ClusterServerPool::handleResponse(Handler* h, ConnectConnection* s, Request p.master().data()); continue; } - auto it = mServs.find(p.addr()); + String addr(p.addr()); + auto it = mServs.find(addr); Server* serv = it == mServs.end() ? nullptr : it->second; + if (!serv) { + if (strstr(p.flags().data(), "myself")) { + serv = s->server(); + } else if (const char* t = strchr(p.addr().data(), '@')) { + addr = String(p.addr().data(), t - p.addr().data()); + it = mServs.find(addr); + serv = it == mServs.end() ? nullptr : it->second; + } + } if (!serv) { const char* flags = p.flags().data(); if (p.role() == Server::Unknown || @@ -127,7 +137,7 @@ void ClusterServerPool::handleResponse(Handler* h, ConnectConnection* s, Request (int)mServPool.size(), p.addr().data()); continue; } - serv = new Server(this, p.addr(), false); + serv = new Server(this, addr, false); serv->setPassword(password()); mServPool.push_back(serv); mServs[serv->addr()] = serv;