From d6ddd047a47df11b50704d88ac39c00013e54768 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 26 Jul 2016 16:32:24 +0200 Subject: [PATCH] Fixed and simplified redis network code. --- cmd/mtredisalize/connection.go | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/cmd/mtredisalize/connection.go b/cmd/mtredisalize/connection.go index 3edb93a..7b0cc83 100644 --- a/cmd/mtredisalize/connection.go +++ b/cmd/mtredisalize/connection.go @@ -21,8 +21,6 @@ var ( redisQueued = []byte("+QUEUED\r\n") redisTrue = []byte(":1\r\n") redisFalse = []byte(":0\r\n") - redisZero = []byte("0\r\n") - redisOne = []byte("1\r\n") ) type Connection struct { @@ -66,11 +64,7 @@ func (c *Connection) Hdel(hash, key []byte) bool { return c.writeError(err) } - if success { - return c.writeMessage(redisOne) - } - - return c.writeMessage(redisZero) + return c.writeBool(success) } func (c *Connection) Hget(hash, key []byte) bool { @@ -153,8 +147,7 @@ func (c *Connection) Hkeys(hash []byte) bool { } func (c *Connection) Ping() bool { - _, err := c.conn.Write(redisPong) - return logError(err) + return c.writeMessage(redisPong) } func (c *Connection) HSpatial(hash, first, second []byte) bool { @@ -183,23 +176,18 @@ func (c *Connection) HSpatial(hash, first, second []byte) bool { func (c *Connection) writeError(err error) bool { logError(err) - _, err = c.conn.Write(redisError) - return logError(err) + return c.writeMessage(redisError) } func (c *Connection) writeEmptyArray() bool { - _, err := c.conn.Write(redisEmptyArray) - return logError(err) + return c.writeMessage(redisEmptyArray) } func (c *Connection) writeBool(b bool) bool { - var err error if b { - _, err = c.conn.Write(redisTrue) - } else { - _, err = c.conn.Write(redisFalse) + return c.writeMessage(redisTrue) } - return logError(err) + return c.writeMessage(redisFalse) } func redisLength(prefix byte, s int) []byte {