From 8b62c900aecfac3aec14c2336d48c2b3fea132bc Mon Sep 17 00:00:00 2001 From: Michael Hoisie Date: Wed, 26 Jun 2013 08:46:58 -0600 Subject: [PATCH] Use Fprintf in commandBytes This avoids an extra copy in WriteString --- redis.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/redis.go b/redis.go index 68c1a57..84724ad 100644 --- a/redis.go +++ b/redis.go @@ -76,9 +76,10 @@ func writeRequest(writer io.Writer, cmd string, args ...string) error { } func commandBytes(cmd string, args ...string) []byte { - cmdbuf := bytes.NewBufferString(fmt.Sprintf("*%d\r\n$%d\r\n%s\r\n", len(args)+1, len(cmd), cmd)) + var cmdbuf bytes.Buffer + fmt.Fprintf(&cmdbuf, "*%d\r\n$%d\r\n%s\r\n", len(args)+1, len(cmd), cmd) for _, s := range args { - cmdbuf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(s), s)) + fmt.Fprintf(&cmdbuf, "$%d\r\n%s\r\n", len(s), s) } return cmdbuf.Bytes() }