redis-cli: Support URIs with IPv6 (#11834)

Co-authored-by: hrliu <hrliu@alauda.io>
This commit is contained in:
DevineLiu 2023-06-30 00:32:01 +08:00 committed by GitHub
parent 07ed0eafa9
commit 6bf9b144ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -352,10 +352,20 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo
path = strchr(curr, '/');
if (*curr != '/') {
host = path ? path - 1 : end;
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);
}