From 8941a74cd91b13dcddd575e9c922dae520371081 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 14 Apr 2015 20:40:39 +0300 Subject: [PATCH] started redis mass insert --- utils/redis.go | 13 +++++++++++++ utils/redis_test.go | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 utils/redis.go create mode 100644 utils/redis_test.go diff --git a/utils/redis.go b/utils/redis.go new file mode 100644 index 000000000..f177e871d --- /dev/null +++ b/utils/redis.go @@ -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 +} diff --git a/utils/redis_test.go b/utils/redis_test.go new file mode 100644 index 000000000..99768a7ac --- /dev/null +++ b/utils/redis_test.go @@ -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) + } +}