mirror of
https://github.com/redis/go-redis.git
synced 2025-08-10 11:03:00 +03:00
Improve nil reply parsing.
This commit is contained in:
20
parser.go
20
parser.go
@@ -231,9 +231,16 @@ func readLine(cn *conn) ([]byte, error) {
|
||||
if isPrefix {
|
||||
return line, errReaderTooSmall
|
||||
}
|
||||
if isNilReply(line) {
|
||||
return nil, Nil
|
||||
}
|
||||
return line, nil
|
||||
}
|
||||
|
||||
func isNilReply(b []byte) bool {
|
||||
return len(b) == 3 && (b[0] == '$' || b[0] == '*') && b[1] == '-' && b[2] == '1'
|
||||
}
|
||||
|
||||
func readN(cn *conn, n int) ([]byte, error) {
|
||||
var b []byte
|
||||
if cap(cn.buf) < n {
|
||||
@@ -251,17 +258,6 @@ func parseErrorReply(cn *conn, line []byte) error {
|
||||
return errorf(string(line[1:]))
|
||||
}
|
||||
|
||||
func isNilReply(b []byte) bool {
|
||||
return len(b) == 3 && b[1] == '-' && b[2] == '1'
|
||||
}
|
||||
|
||||
func parseNilReply(cn *conn, line []byte) error {
|
||||
if isNilReply(line) {
|
||||
return Nil
|
||||
}
|
||||
return fmt.Errorf("redis: can't parse nil reply: %.100", line)
|
||||
}
|
||||
|
||||
func parseStatusReply(cn *conn, line []byte) ([]byte, error) {
|
||||
return line[1:], nil
|
||||
}
|
||||
@@ -282,8 +278,6 @@ func readIntReply(cn *conn) (int64, error) {
|
||||
switch line[0] {
|
||||
case errorReply:
|
||||
return 0, parseErrorReply(cn, line)
|
||||
case stringReply:
|
||||
return 0, parseNilReply(cn, line)
|
||||
case intReply:
|
||||
return parseIntReply(cn, line)
|
||||
default:
|
||||
|
Reference in New Issue
Block a user