Skip to content

Commit f1bd1c0

Browse files
author
Meir Shpilraien (Spielrein)
authored
Added support for ipv6 on cluster set command. (#31)
* Added support for ipv6 on cluster set command. * Run ipv6 tests only if we have ipv6 support. * Fix ipv6 tests * Fix ipv6 tests
1 parent e5a41e1 commit f1bd1c0

File tree

2 files changed

+282
-229
lines changed

2 files changed

+282
-229
lines changed

src/cluster.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,27 @@ static void MR_SetClusterData(RedisModuleString** argv, int argc){
855855

856856
addr = passEnd + 1;
857857

858-
char* ipEnd = strstr(addr, ":");
858+
if (addr[0] == '[') {
859+
addr += 1; /* skip ipv6 opener `[` */
860+
}
861+
862+
/* Find last `:` */
863+
char* iter = strstr(addr, ":");
864+
char* ipEnd = NULL;
865+
while (iter) {
866+
ipEnd = iter;
867+
iter++;
868+
iter = strstr(iter, ":");
869+
}
870+
871+
RedisModule_Assert(ipEnd);
872+
859873
size_t ipSize = ipEnd - addr;
874+
875+
if (addr[ipSize - 1] == ']') {
876+
--ipSize; /* Skip ipv6 closer `]` */
877+
}
878+
860879
char ip[ipSize + 1];
861880
memcpy(ip, addr, ipSize);
862881
ip[ipSize] = '\0';

0 commit comments

Comments
 (0)