forked from redis/go-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal.go
More file actions
50 lines (44 loc) · 1.4 KB
/
external.go
File metadata and controls
50 lines (44 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package redis
import (
"io"
redis "github.com/go-redis/redis/v8/internal/proto"
)
// The creators of this redis client never intended the protocol reader to be made public.
// Unfortunately, we need this specific code to be externalized for use in our proxy.
// To minimize rebasing headaches we'll just put a wrapper around the bits we need.
// Yes, your Computer Science professor would not approve of circumventing the go 'internal'
// package protections but she isn't here to reject this MR. Just be glad I didn't copy/paste
// it instead.
type Reader struct {
r *redis.Reader
}
// NewReader is a simple wrapper around the internal go-redis Reader.
func NewReader(rd io.Reader) *Reader {
return &Reader{
r: redis.NewReader(rd),
}
}
func (r *Reader) ReadReply() (interface{}, error) {
return r.r.ReadReply(sliceParser)
}
// sliceParser implements proto.MultiBulkParse. This is copy/pasted from command.go so that we can make
// some slight modifications if needed.
// func sliceParser(rd *redis.Reader, n int64) (interface{}, error) {
// vals := make([]interface{}, n)
// for i := 0; i < len(vals); i++ {
// v, err := rd.ReadReply(sliceParser)
// if err != nil {
// if err == redis.Nil {
// vals[i] = nil
// continue
// }
// if err, ok := err.(redis.RedisError); ok {
// vals[i] = err
// continue
// }
// return nil, err
// }
// vals[i] = v
// }
// return vals, nil
// }