From d83d4514bd0ae8ad30da09588a448693f17f0f16 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 5 Jun 2020 09:11:12 +0300 Subject: [PATCH] Fix Command parsing --- command.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/command.go b/command.go index c1130e2d..dd7fe4a9 100644 --- a/command.go +++ b/command.go @@ -1935,7 +1935,13 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error { } func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) { - if n != 7 { + const numArgRedis5 = 6 + const numArgRedis6 = 7 + + switch n { + case numArgRedis5, numArgRedis6: + // continue + default: return nil, fmt.Errorf("redis: got %d elements in COMMAND reply, wanted 7", n) } @@ -1989,9 +1995,20 @@ func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) { } cmd.StepCount = int8(stepCount) + for _, flag := range cmd.Flags { + if flag == "readonly" { + cmd.ReadOnly = true + break + } + } + + if n == numArgRedis5 { + return &cmd, nil + } + _, err = rd.ReadReply(func(rd *proto.Reader, n int64) (interface{}, error) { cmd.ACLFlags = make([]string, n) - for i := 0; i < len(cmd.Flags); i++ { + for i := 0; i < len(cmd.ACLFlags); i++ { switch s, err := rd.ReadString(); { case err == Nil: cmd.ACLFlags[i] = "" @@ -2007,13 +2024,6 @@ func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) { return nil, err } - for _, flag := range cmd.Flags { - if flag == "readonly" { - cmd.ReadOnly = true - break - } - } - return &cmd, nil }