Fixes issue #7. mtredisalize implements Redis PING command.

This commit is contained in:
Sascha L. Teichmann 2015-05-26 18:12:55 +02:00
parent 05a95e4f7d
commit 75b2496fa6
2 changed files with 15 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import (
var (
redisOk = []byte("+OK\r\n")
redisPong = []byte("+PONG\r\n")
redisError = []byte("-ERR\r\n")
redisNoSuchBlock = []byte("$-1\r\n")
redisCrnl = []byte("\r\n")
@ -130,6 +131,14 @@ func (c *Connection) Hkeys(hash []byte) bool {
return true
}
func (c *Connection) Ping() bool {
if _, err := c.conn.Write(redisPong); err != nil {
logError(err)
return false
}
return true
}
func (c *Connection) HSpatial(hash, first, second []byte) bool {
var (
err error

View File

@ -11,6 +11,7 @@ import (
"io"
"log"
"strconv"
"strings"
)
const maxBulkStringSize = 8 * 1024 * 1024
@ -130,6 +131,7 @@ type RedisCommands interface {
Exec() bool
Hkeys(hash []byte) bool
HSpatial(hash, first, second []byte) bool
Ping() bool
}
type RedisCommandExecutor struct {
@ -173,7 +175,7 @@ func (rce *RedisCommandExecutor) execute() bool {
log.Printf("WARN: Too less argument for command.")
return false
}
cmd := asString(rce.args[0])
cmd := strings.ToUpper(asString(rce.args[0]))
switch cmd {
case "HGET":
if l < 3 {
@ -235,6 +237,9 @@ func (rce *RedisCommandExecutor) execute() bool {
return false
}
return rce.commands.HSpatial(hash, first, second)
case "PING":
return rce.commands.Ping()
}
log.Printf("WARN: unknown command: '%s'\n", cmd)
return false