This commit is contained in:
Vladimir Mihailenco 2018-07-22 09:27:36 +03:00
parent 585aea1e8d
commit 7c9aa65a40
3 changed files with 26 additions and 24 deletions

View File

@ -47,22 +47,24 @@ func (cn *Conn) IsStale(timeout time.Duration) bool {
return timeout > 0 && time.Since(cn.UsedAt()) > timeout return timeout > 0 && time.Since(cn.UsedAt()) > timeout
} }
func (cn *Conn) SetReadTimeout(timeout time.Duration) error { func (cn *Conn) SetReadTimeout(timeout time.Duration) {
now := time.Now() now := time.Now()
cn.SetUsedAt(now) cn.SetUsedAt(now)
if timeout > 0 { if timeout > 0 {
return cn.netConn.SetReadDeadline(now.Add(timeout)) cn.netConn.SetReadDeadline(now.Add(timeout))
} else {
cn.netConn.SetReadDeadline(noDeadline)
} }
return cn.netConn.SetReadDeadline(noDeadline)
} }
func (cn *Conn) SetWriteTimeout(timeout time.Duration) error { func (cn *Conn) SetWriteTimeout(timeout time.Duration) {
now := time.Now() now := time.Now()
cn.SetUsedAt(now) cn.SetUsedAt(now)
if timeout > 0 { if timeout > 0 {
return cn.netConn.SetWriteDeadline(now.Add(timeout)) cn.netConn.SetWriteDeadline(now.Add(timeout))
} else {
cn.netConn.SetWriteDeadline(noDeadline)
} }
return cn.netConn.SetWriteDeadline(noDeadline)
} }
func (cn *Conn) Write(b []byte) (int, error) { func (cn *Conn) Write(b []byte) (int, error) {

View File

@ -91,11 +91,11 @@ func (r *Reader) ReadReply(m MultiBulkParse) (interface{}, error) {
case ErrorReply: case ErrorReply:
return nil, ParseErrorReply(line) return nil, ParseErrorReply(line)
case StatusReply: case StatusReply:
return parseStatusValue(line), nil return parseTmpStatusReply(line), nil
case IntReply: case IntReply:
return util.ParseInt(line[1:], 10, 64) return util.ParseInt(line[1:], 10, 64)
case StringReply: case StringReply:
return r.readTmpBytesValue(line) return r.readTmpBytesReply(line)
case ArrayReply: case ArrayReply:
n, err := parseArrayLen(line) n, err := parseArrayLen(line)
if err != nil { if err != nil {
@ -130,9 +130,9 @@ func (r *Reader) ReadTmpBytesReply() ([]byte, error) {
case ErrorReply: case ErrorReply:
return nil, ParseErrorReply(line) return nil, ParseErrorReply(line)
case StringReply: case StringReply:
return r.readTmpBytesValue(line) return r.readTmpBytesReply(line)
case StatusReply: case StatusReply:
return parseStatusValue(line), nil return parseTmpStatusReply(line), nil
default: default:
return nil, fmt.Errorf("redis: can't parse string reply: %.100q", line) return nil, fmt.Errorf("redis: can't parse string reply: %.100q", line)
} }
@ -229,7 +229,7 @@ func (r *Reader) ReadScanReply() ([]string, uint64, error) {
return keys, cursor, err return keys, cursor, err
} }
func (r *Reader) readTmpBytesValue(line []byte) ([]byte, error) { func (r *Reader) readTmpBytesReply(line []byte) ([]byte, error) {
if isNilReply(line) { if isNilReply(line) {
return nil, Nil return nil, Nil
} }
@ -294,18 +294,6 @@ func readN(r io.Reader, b []byte, n int) ([]byte, error) {
return b, nil return b, nil
} }
func formatInt(n int64) string {
return strconv.FormatInt(n, 10)
}
func formatUint(u uint64) string {
return strconv.FormatUint(u, 10)
}
func formatFloat(f float64) string {
return strconv.FormatFloat(f, 'f', -1, 64)
}
func isNilReply(b []byte) bool { func isNilReply(b []byte) bool {
return len(b) == 3 && return len(b) == 3 &&
(b[0] == StringReply || b[0] == ArrayReply) && (b[0] == StringReply || b[0] == ArrayReply) &&
@ -316,7 +304,7 @@ func ParseErrorReply(line []byte) error {
return RedisError(string(line[1:])) return RedisError(string(line[1:]))
} }
func parseStatusValue(line []byte) []byte { func parseTmpStatusReply(line []byte) []byte {
return line[1:] return line[1:]
} }

View File

@ -99,3 +99,15 @@ func (w *WriteBuffer) AppendBytes(p []byte) {
w.b = append(w.b, p...) w.b = append(w.b, p...)
w.b = append(w.b, '\r', '\n') w.b = append(w.b, '\r', '\n')
} }
func formatInt(n int64) string {
return strconv.FormatInt(n, 10)
}
func formatUint(u uint64) string {
return strconv.FormatUint(u, 10)
}
func formatFloat(f float64) string {
return strconv.FormatFloat(f, 'f', -1, 64)
}