fix read data

Signed-off-by: monkey <golang@88.com>
This commit is contained in:
monkey 2021-05-18 16:05:17 +08:00
parent 3871963e2d
commit 76393b5b71
1 changed files with 79 additions and 76 deletions

View File

@ -1879,11 +1879,7 @@ func (cmd *XInfoStreamFullCmd) readReply(rd *proto.Reader) error {
case "entries":
cmd.val.Entries, err = readXMessageSlice(rd)
case "groups":
groups, err := rd.ReadReply(readStreamGroups)
if err != nil {
return err
}
cmd.val.Groups = groups.([]XInfoStreamGroup)
cmd.val.Groups, err = readStreamGroups(rd)
default:
return fmt.Errorf("redis: unexpected content %s "+
"in XINFO STREAM reply", key)
@ -1895,9 +1891,13 @@ func (cmd *XInfoStreamFullCmd) readReply(rd *proto.Reader) error {
return nil
}
func readStreamGroups(rd *proto.Reader, n int64) (interface{}, error) {
func readStreamGroups(rd *proto.Reader) ([]XInfoStreamGroup, error) {
n, err := rd.ReadArrayLen()
if err != nil {
return nil, err
}
groups := make([]XInfoStreamGroup, 0, n)
for i := int64(0); i < n; i++ {
for i := 0; i < n; i++ {
nn, err := rd.ReadArrayLen()
if err != nil {
return nil, err
@ -1906,13 +1906,15 @@ func readStreamGroups(rd *proto.Reader, n int64) (interface{}, error) {
return nil, fmt.Errorf("redis: got %d elements in XINFO STREAM FULL reply,"+
"wanted 10", nn)
}
group := XInfoStreamGroup{}
for f := 0; f < 5; f++ {
key, err := rd.ReadString()
if err != nil {
return nil, err
}
group := XInfoStreamGroup{}
switch key {
case "name":
group.Name, err = rd.ReadString()
@ -1932,6 +1934,7 @@ func readStreamGroups(rd *proto.Reader, n int64) (interface{}, error) {
if err != nil {
return nil, err
}
}
groups = append(groups, group)
}
@ -2004,13 +2007,14 @@ func readXInfoStreamConsumers(rd *proto.Reader) ([]XInfoStreamConsumer, error) {
"wanted 8", nn)
}
c := XInfoStreamConsumer{}
for f := 0; f < 4; f++ {
cKey, err := rd.ReadString()
if err != nil {
return nil, err
}
c := XInfoStreamConsumer{}
switch cKey {
case "name":
c.Name, err = rd.ReadString()
@ -2064,11 +2068,10 @@ func readXInfoStreamConsumers(rd *proto.Reader) ([]XInfoStreamConsumer, error) {
return nil, fmt.Errorf("redis: unexpected content %s "+
"in XINFO STREAM reply", cKey)
}
if err != nil {
return nil, err
}
}
consumers = append(consumers, c)
}