diff options
Diffstat (limited to 'Godeps/_workspace/src/github.com/garyburd/redigo/redis/reply.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/garyburd/redigo/redis/reply.go | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/Godeps/_workspace/src/github.com/garyburd/redigo/redis/reply.go b/Godeps/_workspace/src/github.com/garyburd/redigo/redis/reply.go index 5af29bf51..57896147f 100644 --- a/Godeps/_workspace/src/github.com/garyburd/redigo/redis/reply.go +++ b/Godeps/_workspace/src/github.com/garyburd/redigo/redis/reply.go @@ -215,7 +215,9 @@ func Bool(reply interface{}, err error) (bool, error) { return false, fmt.Errorf("redigo: unexpected type for Bool, got type %T", reply) } -// MultiBulk is deprecated. Use Values. +// MultiBulk is a helper that converts an array command reply to a []interface{}. +// +// Deprecated: Use Values instead. func MultiBulk(reply interface{}, err error) ([]interface{}, error) { return Values(reply, err) } // Values is a helper that converts an array command reply to a []interface{}. @@ -271,13 +273,40 @@ func Strings(reply interface{}, err error) ([]string, error) { return nil, fmt.Errorf("redigo: unexpected type for Strings, got type %T", reply) } +// ByteSlices is a helper that converts an array command reply to a [][]byte. +// If err is not equal to nil, then ByteSlices returns nil, err. Nil array +// items are stay nil. ByteSlices returns an error if an array item is not a +// bulk string or nil. +func ByteSlices(reply interface{}, err error) ([][]byte, error) { + if err != nil { + return nil, err + } + switch reply := reply.(type) { + case []interface{}: + result := make([][]byte, len(reply)) + for i := range reply { + if reply[i] == nil { + continue + } + p, ok := reply[i].([]byte) + if !ok { + return nil, fmt.Errorf("redigo: unexpected element type for ByteSlices, got type %T", reply[i]) + } + result[i] = p + } + return result, nil + case nil: + return nil, ErrNil + case Error: + return nil, reply + } + return nil, fmt.Errorf("redigo: unexpected type for ByteSlices, got type %T", reply) +} + // Ints is a helper that converts an array command reply to a []int. If // err is not equal to nil, then Ints returns nil, err. func Ints(reply interface{}, err error) ([]int, error) { var ints []int - if reply == nil { - return ints, ErrNil - } values, err := Values(reply, err) if err != nil { return ints, err |