From 6bf9b144ef722fb301c065125a6bf6cd385841bf Mon Sep 17 00:00:00 2001 From: DevineLiu <23489096+DevineLiu@users.noreply.github.com> Date: Fri, 30 Jun 2023 00:32:01 +0800 Subject: [PATCH] redis-cli: Support URIs with IPv6 (#11834) Co-authored-by: hrliu --- src/cli_common.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cli_common.c b/src/cli_common.c index 0b13db5dc..421e7d34a 100644 --- a/src/cli_common.c +++ b/src/cli_common.c @@ -352,9 +352,19 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo path = strchr(curr, '/'); if (*curr != '/') { host = path ? path - 1 : end; - if ((port = strchr(curr, ':'))) { - connInfo->hostport = atoi(port + 1); - host = port - 1; + if (*curr == '[') { + curr += 1; + if ((port = strchr(curr, ']'))) { + if (*(port+1) == ':') { + connInfo->hostport = atoi(port + 2); + } + host = port - 1; + } + } else { + if ((port = strchr(curr, ':'))) { + connInfo->hostport = atoi(port + 1); + host = port - 1; + } } sdsfree(connInfo->hostip); connInfo->hostip = sdsnewlen(curr, host - curr + 1);