From 3257aa87ca2591f0ede5d6293c47f47c6e0828bd Mon Sep 17 00:00:00 2001 From: sewenew Date: Tue, 8 Oct 2024 22:54:56 +0800 Subject: [PATCH] support IPv6 redirection message. --- src/sw/redis++/shards.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sw/redis++/shards.cpp b/src/sw/redis++/shards.cpp index fa7e1311..fc58eeae 100644 --- a/src/sw/redis++/shards.cpp +++ b/src/sw/redis++/shards.cpp @@ -27,11 +27,12 @@ RedirectionError::RedirectionError(const std::string &msg): ReplyError(msg) { std::pair RedirectionError::_parse_error(const std::string &msg) const { // "slot ip:port" auto space_pos = msg.find(" "); - auto colon_pos = msg.find(":"); + // There're colons in IPv6 address, so we need to find the last colon. + auto colon_pos = msg.rfind(":"); if (space_pos == std::string::npos || colon_pos == std::string::npos || colon_pos < space_pos) { - throw ProtoError("Invalid ASK error message: " + msg); + throw ProtoError("invalid redirection error message: " + msg); } try { @@ -43,7 +44,7 @@ std::pair RedirectionError::_parse_error(const std::string &msg) con return {slot, {host, port}}; } catch (const std::exception &) { - throw ProtoError("Invalid ASK error message: " + msg); + throw ProtoError("invalid redirection error message: " + msg); } }