Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cluster slots reply checking logic for Redis 7 #2108

Merged
merged 2 commits into from
Jun 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2628,8 +2628,9 @@ func (cmd *ScanCmd) Iterator() *ScanIterator {
//------------------------------------------------------------------------------

type ClusterNode struct {
ID string
Addr string
ID string
Addr string
NetworkingMetadata map[string]string
}

type ClusterSlot struct {
Expand Down Expand Up @@ -2700,8 +2701,8 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error {
if err != nil {
return nil, err
}
if n != 2 && n != 3 {
err := fmt.Errorf("got %d elements in cluster info address, expected 2 or 3", n)
if n < 2 || n > 4 {
err := fmt.Errorf("got %d elements in cluster info address, shoud be between 2 and 4", n)
return nil, err
}

Expand All @@ -2717,13 +2718,36 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error {

nodes[j].Addr = net.JoinHostPort(ip, port)

if n == 3 {
if n >= 3 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have 4 replies, then we should also read (and probably discard) the 4th reply as well?

id, err := rd.ReadString()
if err != nil {
return nil, err
}
nodes[j].ID = id
}
if n == 4 {
networkingMetadata := make(map[string]string)
metadataLength, err := rd.ReadArrayLen()
if err != nil {
return nil, err
}
if metadataLength%2 != 0 {
err := fmt.Errorf("the array length of metadata must be a even number, current: %d", metadataLength)
return nil, err
}
for i := 0; i < metadataLength; i = i + 2 {
key, err := rd.ReadString()
if err != nil {
return nil, err
}
value, err := rd.ReadString()
if err != nil {
return nil, err
}
networkingMetadata[key] = value
}
nodes[j].NetworkingMetadata = networkingMetadata
}
}

cmd.val[i] = ClusterSlot{
Expand Down