Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bc9d5c8

Browse files
authoredAug 13, 2021
Add Cmd.Slice helper to cast to []interface{} (#1859)
1 parent 4029656 commit bc9d5c8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎command.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@ func (cmd *Cmd) Bool() (bool, error) {
315315
}
316316
}
317317

318+
func (cmd *Cmd) Slice() ([]interface{}, error) {
319+
if cmd.err != nil {
320+
return nil, cmd.err
321+
}
322+
switch val := cmd.val.(type) {
323+
case []interface{}:
324+
return val, nil
325+
default:
326+
return nil, fmt.Errorf("redis: unexpected type=%T for Slice", val)
327+
}
328+
}
329+
318330
func (cmd *Cmd) readReply(rd *proto.Reader) (err error) {
319331
cmd.val, err = rd.ReadReply(sliceParser)
320332
return err

0 commit comments

Comments
 (0)
Please sign in to comment.