From 75b2496fa65189f59adaf15ab741f2ac1161f19a Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 26 May 2015 18:12:55 +0200 Subject: [PATCH] Fixes issue #7. mtredisalize implements Redis PING command. --- cmd/mtredisalize/connection.go | 9 +++++++++ cmd/mtredisalize/parser.go | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/mtredisalize/connection.go b/cmd/mtredisalize/connection.go index b834030..64cea82 100644 --- a/cmd/mtredisalize/connection.go +++ b/cmd/mtredisalize/connection.go @@ -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 diff --git a/cmd/mtredisalize/parser.go b/cmd/mtredisalize/parser.go index bd38351..daaae23 100644 --- a/cmd/mtredisalize/parser.go +++ b/cmd/mtredisalize/parser.go @@ -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