started redis mass insert

This commit is contained in:
Radu Ioan Fericean
2015-04-14 20:40:39 +03:00
parent 3856f6ec81
commit 8941a74cd9
2 changed files with 23 additions and 0 deletions

13
utils/redis.go Normal file
View File

@@ -0,0 +1,13 @@
package utils
import "fmt"
func GenRedisProtocol(cmd ...string) string {
proto := ""
proto += fmt.Sprintf("*%d\r\n", len(cmd))
for _, arg := range cmd {
proto += fmt.Sprintf("$%d\r\n", len(arg))
proto += fmt.Sprintf("%s\r\n", arg)
}
return proto
}

10
utils/redis_test.go Normal file
View File

@@ -0,0 +1,10 @@
package utils
import "testing"
func TestRedisGenProto(t *testing.T) {
cmd := GenRedisProtocol("SET", "mykey", "Hello World!")
if cmd != "*3\r\n$3\r\nSET\r\n$5\r\nmykey\r\n$12\r\nHello World!\r\n" {
t.Error("Wrong redis protocol command: " + cmd)
}
}