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