From bc9d5c8d3af4780baecc5b76e3f37a9c3d18ab42 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 13 Aug 2021 10:37:54 +0300 Subject: [PATCH] Add Cmd.Slice helper to cast to []interface{} (#1859) --- 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