mirror of
				https://bitbucket.org/s_l_teichmann/mtsatellite
				synced 2025-11-04 09:55:34 +01:00 
			
		
		
		
	Fixes issue #7. mtredisalize implements Redis PING command.
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user