Add Cmd.Slice helper to cast to []interface{} (#1859)

This commit is contained in:
Vladimir Mihailenco 2021-08-13 10:37:54 +03:00 committed by GitHub
parent 4029656ad5
commit bc9d5c8d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -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) { func (cmd *Cmd) readReply(rd *proto.Reader) (err error) {
cmd.val, err = rd.ReadReply(sliceParser) cmd.val, err = rd.ReadReply(sliceParser)
return err return err