From 7c9aa65a40606ea905bc1bb55e7ec69d57bbe986 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 22 Jul 2018 09:27:36 +0300 Subject: [PATCH] Cleanup --- internal/pool/conn.go | 14 ++++++++------ internal/proto/reader.go | 24 ++++++------------------ internal/proto/write_buffer.go | 12 ++++++++++++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/internal/pool/conn.go b/internal/pool/conn.go index 8af51d9..acaf366 100644 --- a/internal/pool/conn.go +++ b/internal/pool/conn.go @@ -47,22 +47,24 @@ func (cn *Conn) IsStale(timeout time.Duration) bool { 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() cn.SetUsedAt(now) 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() cn.SetUsedAt(now) 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) { diff --git a/internal/proto/reader.go b/internal/proto/reader.go index d5d6953..8c28c7b 100644 --- a/internal/proto/reader.go +++ b/internal/proto/reader.go @@ -91,11 +91,11 @@ func (r *Reader) ReadReply(m MultiBulkParse) (interface{}, error) { case ErrorReply: return nil, ParseErrorReply(line) case StatusReply: - return parseStatusValue(line), nil + return parseTmpStatusReply(line), nil case IntReply: return util.ParseInt(line[1:], 10, 64) case StringReply: - return r.readTmpBytesValue(line) + return r.readTmpBytesReply(line) case ArrayReply: n, err := parseArrayLen(line) if err != nil { @@ -130,9 +130,9 @@ func (r *Reader) ReadTmpBytesReply() ([]byte, error) { case ErrorReply: return nil, ParseErrorReply(line) case StringReply: - return r.readTmpBytesValue(line) + return r.readTmpBytesReply(line) case StatusReply: - return parseStatusValue(line), nil + return parseTmpStatusReply(line), nil default: 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 } -func (r *Reader) readTmpBytesValue(line []byte) ([]byte, error) { +func (r *Reader) readTmpBytesReply(line []byte) ([]byte, error) { if isNilReply(line) { return nil, Nil } @@ -294,18 +294,6 @@ func readN(r io.Reader, b []byte, n int) ([]byte, error) { 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 { return len(b) == 3 && (b[0] == StringReply || b[0] == ArrayReply) && @@ -316,7 +304,7 @@ func ParseErrorReply(line []byte) error { return RedisError(string(line[1:])) } -func parseStatusValue(line []byte) []byte { +func parseTmpStatusReply(line []byte) []byte { return line[1:] } diff --git a/internal/proto/write_buffer.go b/internal/proto/write_buffer.go index cc4014f..664f4c3 100644 --- a/internal/proto/write_buffer.go +++ b/internal/proto/write_buffer.go @@ -99,3 +99,15 @@ func (w *WriteBuffer) AppendBytes(p []byte) { w.b = append(w.b, p...) 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) +}