From e1c0580d65bede850c55318bcd9c62a68ad9c75e Mon Sep 17 00:00:00 2001 From: Roman Poleguev <30798101+Pomkaize@users.noreply.github.com> Date: Mon, 19 Sep 2022 20:31:21 +0300 Subject: [PATCH] Fix CLUSTER_NODES ipv6 address parsing (#2269) --- .../client/lib/commands/CLUSTER_NODES.spec.ts | 25 +++++++++++++++++++ packages/client/lib/commands/CLUSTER_NODES.ts | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/client/lib/commands/CLUSTER_NODES.spec.ts b/packages/client/lib/commands/CLUSTER_NODES.spec.ts index 8e0efc6b1c..5c6cb74d6c 100644 --- a/packages/client/lib/commands/CLUSTER_NODES.spec.ts +++ b/packages/client/lib/commands/CLUSTER_NODES.spec.ts @@ -73,6 +73,31 @@ describe('CLUSTER NODES', () => { ); }); + it('should support ipv6 addresses', () => { + assert.deepEqual( + transformReply( + 'id 2a02:6b8:c21:330d:0:1589:ebbe:b1a0:6379@16379 master - 0 0 0 connected 0-549\n' + ), + [{ + id: 'id', + address: '2a02:6b8:c21:330d:0:1589:ebbe:b1a0:6379@16379', + host: '2a02:6b8:c21:330d:0:1589:ebbe:b1a0', + port: 6379, + cport: 16379, + flags: ['master'], + pingSent: 0, + pongRecv: 0, + configEpoch: 0, + linkState: RedisClusterNodeLinkStates.CONNECTED, + slots: [{ + from: 0, + to: 549 + }], + replicas: [] + }] + ); + }); + it.skip('with importing slots', () => { assert.deepEqual( transformReply( diff --git a/packages/client/lib/commands/CLUSTER_NODES.ts b/packages/client/lib/commands/CLUSTER_NODES.ts index 846bbccf10..7c433da5f1 100644 --- a/packages/client/lib/commands/CLUSTER_NODES.ts +++ b/packages/client/lib/commands/CLUSTER_NODES.ts @@ -85,7 +85,7 @@ export function transformReply(reply: string): Array { } function transformNodeAddress(address: string): RedisClusterNodeAddress { - const indexOfColon = address.indexOf(':'), + const indexOfColon = address.lastIndexOf(':'), indexOfAt = address.indexOf('@', indexOfColon), host = address.substring(0, indexOfColon);