mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-15 14:50:21 +01:00
Fixed and simplified redis network code.
This commit is contained in:
parent
60f43c9f52
commit
d6ddd047a4
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user