mirror of https://github.com/go-redis/redis.git
update cluster slots reply checking logic for Redis 7 (#2108)
fix: update cluster slots reply checking logic for redis 7
This commit is contained in:
parent
1980be0f9f
commit
52af8ba852
30
command.go
30
command.go
|
@ -2630,6 +2630,7 @@ func (cmd *ScanCmd) Iterator() *ScanIterator {
|
||||||
type ClusterNode struct {
|
type ClusterNode struct {
|
||||||
ID string
|
ID string
|
||||||
Addr string
|
Addr string
|
||||||
|
NetworkingMetadata map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClusterSlot struct {
|
type ClusterSlot struct {
|
||||||
|
@ -2700,8 +2701,8 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if n != 2 && n != 3 {
|
if n < 2 || n > 4 {
|
||||||
err := fmt.Errorf("got %d elements in cluster info address, expected 2 or 3", n)
|
err := fmt.Errorf("got %d elements in cluster info address, shoud be between 2 and 4", n)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2717,13 +2718,36 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error {
|
||||||
|
|
||||||
nodes[j].Addr = net.JoinHostPort(ip, port)
|
nodes[j].Addr = net.JoinHostPort(ip, port)
|
||||||
|
|
||||||
if n == 3 {
|
if n >= 3 {
|
||||||
id, err := rd.ReadString()
|
id, err := rd.ReadString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nodes[j].ID = id
|
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{
|
cmd.val[i] = ClusterSlot{
|
||||||
|
|
Loading…
Reference in New Issue