Skip to content

Commit

Permalink
use net.JoinHostPort when constructing addrs from cluster topo
Browse files Browse the repository at this point in the history
Fixes #288
  • Loading branch information
Brian Picciano committed Jul 26, 2021
1 parent 0b40fbf commit 20a0a86
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cluster_topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (tss *topoSlotSet) UnmarshalRESP(br *bufio.Reader) error {
}

node := ClusterNode{
Addr: ip + ":" + port,
Addr: net.JoinHostPort(ip, port),
ID: id,
Slots: [][2]uint16{tss.slots},
}
Expand Down
32 changes: 32 additions & 0 deletions cluster_topo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,35 @@ func TestClusterTopoSplitSlots(t *T) {
}

}

func TestIPV6ClusterTopo(t *T) {
clusterSlotsResp := respArr(
respArr(0, 0,
respArr("8ffd:50::d4eb", "7001", "90900dd4ef2182825bc853c448737b2ba9975a50"),
),
)
expTopo := ClusterTopo{
ClusterNode{
Slots: [][2]uint16{{0, 1}},
Addr: "[8ffd:50::d4eb]:7001", ID: "90900dd4ef2182825bc853c448737b2ba9975a50",
},
}

// unmarshal the resp into a Topo and make sure it matches expTopo
{
buf := new(bytes.Buffer)
require.Nil(t, clusterSlotsResp.MarshalRESP(buf))
var topo ClusterTopo
require.Nil(t, topo.UnmarshalRESP(bufio.NewReader(buf)))
assert.Equal(t, expTopo, topo)
}

// marshal Topo, then re-unmarshal, and make sure it still matches
{
buf := new(bytes.Buffer)
require.Nil(t, expTopo.MarshalRESP(buf))
var topo ClusterTopo
require.Nil(t, topo.UnmarshalRESP(bufio.NewReader(buf)))
assert.Equal(t, expTopo, topo)
}
}

0 comments on commit 20a0a86

Please sign in to comment.