Simplified Redis code a bit when writing booleans to client.

This commit is contained in:
Sascha L. Teichmann 2015-05-26 19:25:26 +02:00
parent af469a3173
commit 29a5abeec4

View File

@ -19,6 +19,8 @@ var (
redisCrnl = []byte("\r\n")
redisEmptyArray = []byte("*0\r\n")
redisQueued = []byte("+QUEUED\r\n")
redisTrue = []byte(":1\r\n")
redisFalse = []byte(":0\r\n")
)
type Connection struct {
@ -188,15 +190,14 @@ func (c *Connection) writeEmptyArray() bool {
return true
}
func asInt(b bool) int {
if b {
return 1
}
return 0
}
func (c *Connection) writeBool(b bool) bool {
if _, err := c.conn.Write([]byte(fmt.Sprintf(":%d\r\n", asInt(b)))); err != nil {
var err error
if b {
_, err = c.conn.Write(redisTrue)
} else {
_, err = c.conn.Write(redisFalse)
}
if err != nil {
logError(err)
return false
}