Redis client: Pulled micro optimisation over from server when constructing bulk strings.

This commit is contained in:
Sascha L. Teichmann 2015-06-28 14:41:07 +02:00
parent 2d00eb9567
commit b66c7fdff3

View File

@ -8,6 +8,7 @@ import (
"bufio"
"fmt"
"net"
"strconv"
)
type RedisClient struct {
@ -34,8 +35,13 @@ func (client *RedisClient) writeArray(size int) (err error) {
return
}
func redisLength(prefix byte, s int) []byte {
buf := append(make([]byte, 0, 16), prefix)
return append(strconv.AppendInt(buf, int64(s), 10), '\r', '\n')
}
func (client *RedisClient) writeBulkString(data []byte) (err error) {
if _, err = client.conn.Write([]byte(fmt.Sprintf("$%d\r\n", len(data)))); err != nil {
if _, err = client.conn.Write(redisLength('$', len(data))); err != nil {
return
}
if _, err = client.conn.Write(data); err != nil {