Avoid copy lock value and split push

This commit is contained in:
Steve Coffman 2019-08-11 18:13:37 -04:00
parent 13c8ecfd5a
commit ccf2b7b321
3 changed files with 60 additions and 15 deletions

View file

@ -7,12 +7,15 @@ import (
"fmt"
"io"
"net"
"strconv"
"strings"
"unicode"
)
type connection struct {
reader *bufio.Reader
conn net.Conn
cmdMaxBytes int
closed bool
}
@ -63,6 +66,20 @@ func (c *connection) read() (string, error) {
if strings.HasPrefix(str, "ERR ") {
return "", errors.New(str[4:])
}
if strings.HasPrefix(str, "STARTED ") {
ss := strings.FieldsFunc(str, func(r rune) bool {
if unicode.IsSpace(r) || r == '(' || r == ')' {
return true
}
return false
})
bufferSize, err := strconv.Atoi(ss[len(ss)-1])
if err != nil {
return "", errors.New(fmt.Sprintf("Unable to parse STARTED response: %s", str))
}
c.cmdMaxBytes = bufferSize
}
return str, nil
}