From 97039c229c83b90cbc350acb4df44b72b89a9403 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 13 Jul 2014 15:07:37 +0300 Subject: [PATCH] Reuse write buffer. --- pool.go | 2 ++ redis.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pool.go b/pool.go index 6fe4538..fed110d 100644 --- a/pool.go +++ b/pool.go @@ -35,6 +35,7 @@ type pool interface { type conn struct { netcn net.Conn rd *bufio.Reader + buf []byte inUse bool usedAt time.Time @@ -53,6 +54,7 @@ func newConnFunc(dial func() (net.Conn, error)) func() (*conn, error) { } cn := &conn{ netcn: netcn, + buf: make([]byte, 0, 64), } cn.rd = bufio.NewReader(cn) return cn, nil diff --git a/redis.go b/redis.go index 1c5f6c3..6c64225 100644 --- a/redis.go +++ b/redis.go @@ -14,7 +14,7 @@ type baseClient struct { } func (c *baseClient) writeCmd(cn *conn, cmds ...Cmder) error { - buf := make([]byte, 0, 64) + buf := cn.buf[:0] for _, cmd := range cmds { buf = appendArgs(buf, cmd.args()) }