mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Don't use fmt.Sprintf when sending size of a redis bulk string.
This commit is contained in:
parent
a165bcd53a
commit
f80d9e452c
@ -6,9 +6,9 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -121,7 +121,7 @@ func (c *Connection) Hkeys(hash []byte) bool {
|
||||
return c.writeEmptyArray()
|
||||
}
|
||||
|
||||
if _, err := c.conn.Write([]byte(fmt.Sprintf("*%d\r\n", n))); err != nil {
|
||||
if _, err := c.conn.Write(redisLength('*', n)); err != nil {
|
||||
logError(err)
|
||||
return false
|
||||
}
|
||||
@ -204,8 +204,13 @@ func (c *Connection) writeBool(b bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
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 (c *Connection) writeBoolArray(arr []bool) bool {
|
||||
if _, err := c.conn.Write([]byte(fmt.Sprintf("*%d\r\n", len(arr)))); err != nil {
|
||||
if _, err := c.conn.Write(redisLength('*', len(arr))); err != nil {
|
||||
logError(err)
|
||||
return false
|
||||
}
|
||||
@ -246,7 +251,7 @@ func (c *Connection) writeBulkString(data []byte) (err error) {
|
||||
if data == nil {
|
||||
_, err = con.Write(redisNoSuchBlock)
|
||||
} else {
|
||||
if _, err = con.Write([]byte(fmt.Sprintf("$%d\r\n", len(data)))); err != nil {
|
||||
if _, err = con.Write(redisLength('$', len(data))); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err = con.Write(data); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user