mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-08 03:00:26 +01:00
Simplified Redis code a bit when writing booleans to client.
This commit is contained in:
parent
af469a3173
commit
29a5abeec4
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user