From b74671ae63c5a6558b50ba9be311351caf60a743 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 2 Jun 2015 20:10:56 +0200 Subject: [PATCH] Simplified error handling in Redis connection handler. This also reduces the diff size to the syndtr-goleveldb branch. --- cmd/mtredisalize/connection.go | 44 +++++++++++++--------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/cmd/mtredisalize/connection.go b/cmd/mtredisalize/connection.go index 78aae99..28021a8 100644 --- a/cmd/mtredisalize/connection.go +++ b/cmd/mtredisalize/connection.go @@ -50,8 +50,9 @@ func (c *Connection) Run() { log.Println("client disconnected") } -func logError(err error) { - log.Printf("ERROR: %s", err) +func logError(err error) bool { + log.Printf("ERROR: %s\n", err) + return false } func (c *Connection) Hget(hash, key []byte) bool { @@ -122,14 +123,12 @@ func (c *Connection) Hkeys(hash []byte) bool { } if _, err := c.conn.Write(redisLength('*', n)); err != nil { - logError(err) - return false + return logError(err) } for key := range keys { if err = c.writeBulkString(key); err != nil { - logError(err) - return false + return logError(err) } } return true @@ -137,8 +136,7 @@ func (c *Connection) Hkeys(hash []byte) bool { func (c *Connection) Ping() bool { if _, err := c.conn.Write(redisPong); err != nil { - logError(err) - return false + return logError(err) } return true } @@ -157,18 +155,15 @@ func (c *Connection) HSpatial(hash, first, second []byte) bool { for block := range blocks { if err = c.writeBulkString(block.Key); err != nil { - logError(err) - return false + return logError(err) } if err = c.writeBulkString(block.Data); err != nil { - logError(err) - return false + return logError(err) } } if err = c.writeBulkString(nil); err != nil { - logError(err) - return false + return logError(err) } return true } @@ -176,16 +171,14 @@ func (c *Connection) HSpatial(hash, first, second []byte) bool { func (c *Connection) writeError(err error) bool { logError(err) if _, err = c.conn.Write(redisError); err != nil { - logError(err) - return false + return logError(err) } return true } func (c *Connection) writeEmptyArray() bool { if _, err := c.conn.Write(redisEmptyArray); err != nil { - logError(err) - return false + return logError(err) } return true } @@ -198,8 +191,7 @@ func (c *Connection) writeBool(b bool) bool { _, err = c.conn.Write(redisFalse) } if err != nil { - logError(err) - return false + return logError(err) } return true } @@ -211,8 +203,7 @@ func redisLength(prefix byte, s int) []byte { func (c *Connection) writeBoolArray(arr []bool) bool { if _, err := c.conn.Write(redisLength('*', len(arr))); err != nil { - logError(err) - return false + return logError(err) } for _, b := range arr { if !c.writeBool(b) { @@ -224,24 +215,21 @@ func (c *Connection) writeBoolArray(arr []bool) bool { func (c *Connection) writeOk() bool { if _, err := c.conn.Write(redisOk); err != nil { - logError(err) - return false + return logError(err) } return true } func (c *Connection) writeQueued() bool { if _, err := c.conn.Write(redisQueued); err != nil { - logError(err) - return false + return logError(err) } return true } func (c *Connection) writeBlock(data []byte) bool { if err := c.writeBulkString(data); err != nil { - logError(err) - return false + return logError(err) } return true }