mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
started redis mass insert
This commit is contained in:
13
utils/redis.go
Normal file
13
utils/redis.go
Normal 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
10
utils/redis_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user