func listConfig(client *redis.Client, key string) { value, err := client.Hgetall(key) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } for key, value := range value.StringMap() { fmt.Println(fmt.Sprintf("%s=%s", key, value)) } }
func QuitClient(t *testing.T, client redis.Client) { // flush it e := client.Quit() if e != nil { t.Fatalf("on Quit - %s", e) } }
func doLpop(id string, signal chan int, client redis.Client, cnt int) { key := "list-L-" + id for i := 0; i < cnt; i++ { client.Lpop(key) } signal <- 1 }
func doGet (id string, signal chan int, client redis.Client, cnt int) { key := "set-" + id; for i:=0;i<cnt;i++ { client.Get(key); } signal <- 1; }
func FlushClient(t *testing.T, client redis.Client) { // flush it e := client.Flushdb() if e != nil { t.Fatalf("on Flushdb - %s", e) } }
func doDecr (id string, signal chan int, client redis.Client, cnt int) { key := "ctr-" + id; for i:=0;i<cnt;i++ { client.Decr(key); } signal <- 1; }
func doRpop (id string, signal chan int, client redis.Client, cnt int) { key := "list-R" + id; for i:=0;i<cnt;i++ { client.Rpop(key); } signal <- 1; }
func doIncr(id string, signal chan int, client redis.Client, cnt int) { key := "ctr-" + id for i := 0; i < cnt; i++ { client.Incr(key) } signal <- 1 }
func doSet (id string, signal chan int, client redis.Client, cnt int) { key := "set-" + id; value := strings.Bytes("foo"); for i:=0;i<cnt;i++ { client.Set(key, value); } signal <- 1; }
func doRpush(id string, signal chan int, client redis.Client, cnt int) { key := "list-R-" + id value := []byte("foo") for i := 0; i < cnt; i++ { client.Rpush(key, value) } signal <- 1 }
func doRpush (id string, signal chan int, client redis.Client, cnt int) { key := "list-R-" + id; value := strings.Bytes("foo"); for i:=0;i<cnt;i++ { client.Rpush(key, value); } signal <- 1; }
func doSet(id string, signal chan int, client redis.Client, cnt int) { key := "set-" + id value := []byte("foo") for i := 0; i < cnt; i++ { client.Set(key, value) } signal <- 1 }
func doLpush(id string, signal chan int, client redis.Client, cnt int) { key := "list-L-" + id value := strings.Bytes("foo") for i := 0; i < cnt; i++ { client.Lpush(key, value) } signal <- 1 }
func removeConfig(client *redis.Client, key string, name string) { _, err := client.Hdel(key, name) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }
func doPing(client redis.Client, cnt int) (delta int64) { t0 := time.Nanoseconds() for i := 0; i < cnt; i++ { client.Ping() } delta = time.Nanoseconds() - t0 client.Flushdb() return }
func doPing(client redis.Client, cnt int) (delta time.Duration) { t0 := time.Now() for i := 0; i < cnt; i++ { client.Ping() } delta = time.Now().Sub(t0) client.Flushdb() return }
func doRpop(client redis.Client, cnt int) (delta time.Duration) { key := "list-R" t0 := time.Now() for i := 0; i < cnt; i++ { client.Lpop(key) } delta = time.Now().Sub(t0) return }
func doRpop(client redis.Client, cnt int) (delta int64) { key := "list-R" t0 := time.Nanoseconds() for i := 0; i < cnt; i++ { client.Lpop(key) } delta = time.Nanoseconds() - t0 return }
func doIncr(client redis.Client, cnt int) (delta int64) { key := "ctr" t0 := time.Nanoseconds() for i := 0; i < cnt; i++ { client.Incr(key) } delta = time.Nanoseconds() - t0 client.Flushdb() return }
func doRpush(client redis.Client, cnt int) (delta int64) { key := "list-R" value := strings.Bytes("foo") t0 := time.Nanoseconds() for i := 0; i < cnt; i++ { client.Lpush(key, value) } delta = time.Nanoseconds() - t0 return }
func doGet(client redis.Client, cnt int) (delta time.Duration) { key := "ctr" t0 := time.Now() for i := 0; i < cnt; i++ { client.Get(key) } delta = time.Now().Sub(t0) client.Flushdb() return }
func doSet(client redis.Client, cnt int) (delta int64) { key := "ctr" value := strings.Bytes("foo") t0 := time.Nanoseconds() for i := 0; i < cnt; i++ { client.Set(key, value) } delta = time.Nanoseconds() - t0 client.Flushdb() return }
func doSadd(client redis.Client, cnt int) (delta time.Duration) { key := "set" value := []byte("one") t0 := time.Now() for i := 0; i < cnt; i++ { client.Sadd(key, value) } delta = time.Now().Sub(t0) client.Flushdb() return }
func flushAndQuitOnCompletion(t *testing.T, client redis.Client) { // flush it e := client.Flushdb() if e != nil { t.Errorf("on Flushdb - %s", e) } e = client.Quit() if e != nil { t.Errorf("on Quit - %s", e) } }
func doSadd(client redis.Client, cnt int) (delta int64) { key := "set" value := []byte("one") t0 := time.Nanoseconds() for i := 0; i < cnt; i++ { client.Sadd(key, value) } delta = time.Nanoseconds() - t0 client.Flushdb() return }
func addConfig(client *redis.Client, key string, nameAndValue string) { parts := strings.Split(nameAndValue, "=") name := parts[0] value := strings.Join(parts[1:len(parts)], "=") _, err := client.Hset(key, name, value) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }
func run(client *redis.Client, key string, command string) { value, err := client.Hgetall(key) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(111) } env := make([]string, 0) for key, value := range value.StringMap() { env = append(env, fmt.Sprintf("%s=%s", key, value)) } syscall.Exec("/bin/sh", []string{"/bin/sh", "-c", command}, env) }
func dump_db(port int, db int, output io.Writer) { var client redis.Client if port != 0 { client.Addr = "127.0.0.1:" + strconv.Itoa(port) } if db != 0 { client.Db = db } fmt.Fprintf(output, "FLUSHDB\r\n") keys, err := client.Keys("*") if err != nil { println("Redis-dump failed", err.Error()) return } for _, key := range keys { typ, _ := client.Type(key) if typ == "string" { data, _ := client.Get(key) fmt.Fprintf(output, "SET %s %d\r\n%s\r\n", key, len(data), data) } else if typ == "list" { llen, _ := client.Llen(key) for i := 0; i < llen; i++ { data, _ := client.Lindex(key, i) fmt.Fprintf(output, "RPUSH %s %d\r\n%s\r\n", key, len(data), data) } } else if typ == "set" { members, _ := client.Smembers(key) for _, data := range members { fmt.Fprintf(output, "SADD %s %d\r\n%s\r\n", key, len(data), data) } } } }
func doPing (id string, signal chan int, client redis.Client, cnt int) { for i:=0;i<cnt;i++ { client.Ping(); } signal <- 1; }
func doRpush(client redis.Client, cnt int) (delta time.Duration) { key := "list-R" value := []byte("foo") t0 := time.Now() for i := 0; i < cnt; i++ { client.Lpush(key, value) } delta = time.Now().Sub(t0) return }