From dfd360572fd5f57edb21b7f28242f03513872596 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 13 Aug 2021 10:17:44 +0300 Subject: [PATCH] Add Cmd.Slice helper to cast to []interface{} --- command.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/command.go b/command.go index 6f77258..c6f1ed4 100644 --- a/command.go +++ b/command.go @@ -315,6 +315,18 @@ func (cmd *Cmd) Bool() (bool, error) { } } +func (cmd *Cmd) Slice() ([]interface{}, error) { + if cmd.err != nil { + return nil, cmd.err + } + switch val := cmd.val.(type) { + case []interface{}: + return val, nil + default: + return nil, fmt.Errorf("redis: unexpected type=%T for Slice", val) + } +} + func (cmd *Cmd) readReply(rd *proto.Reader) (err error) { cmd.val, err = rd.ReadReply(sliceParser) return err