Simplified error handling in Redis connection handler.

This also reduces the diff size to the syndtr-goleveldb branch.
This commit is contained in:
Sascha L. Teichmann 2015-06-02 20:10:56 +02:00
parent 5fb85c3c68
commit b74671ae63

View File

@ -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
}