mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Redis client: Pulled micro optimisation over from server when constructing bulk strings.
This commit is contained in:
parent
2d00eb9567
commit
b66c7fdff3
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user