func TestCmdEval(t *testing.T) { c := getTestConn() defer c.Close() if v, err := ledis.Strings(c.Do("eval", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "key1", "key2", "first", "second")); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(v, []string{"key1", "key2", "first", "second"}) { t.Fatal(fmt.Sprintf("%v", v)) } if v, err := ledis.Strings(c.Do("eval", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "key1", "key2", "first", "second")); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(v, []string{"key1", "key2", "first", "second"}) { t.Fatal(fmt.Sprintf("%v", v)) } var sha1 string var err error if sha1, err = ledis.String(c.Do("script", "load", "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}")); err != nil { t.Fatal(err) } else if len(sha1) != 40 { t.Fatal(sha1) } if v, err := ledis.Strings(c.Do("evalsha", sha1, 2, "key1", "key2", "first", "second")); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(v, []string{"key1", "key2", "first", "second"}) { t.Fatal(fmt.Sprintf("%v", v)) } if ay, err := ledis.Values(c.Do("script", "exists", sha1, "01234567890123456789")); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(ay, []interface{}{int64(1), int64(0)}) { t.Fatal(fmt.Sprintf("%v", ay)) } if ok, err := ledis.String(c.Do("script", "flush")); err != nil { t.Fatal(err) } else if ok != "OK" { t.Fatal(ok) } if ay, err := ledis.Values(c.Do("script", "exists", sha1)); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(ay, []interface{}{int64(0)}) { t.Fatal(fmt.Sprintf("%v", ay)) } }
func checkScan(t *testing.T, c *ledis.Client, cmd string) { if ay, err := ledis.Values(c.Do(cmd, "", "count", 5)); err != nil { t.Fatal(err) } else if len(ay) != 2 { t.Fatal(len(ay)) } else if n := ay[0].([]byte); string(n) != "4" { t.Fatal(string(n)) } else { checkScanValues(t, ay[1], 0, 1, 2, 3, 4) } if ay, err := ledis.Values(c.Do(cmd, "4", "count", 6)); err != nil { t.Fatal(err) } else if len(ay) != 2 { t.Fatal(len(ay)) } else if n := ay[0].([]byte); string(n) != "" { t.Fatal(string(n)) } else { checkScanValues(t, ay[1], 5, 6, 7, 8, 9) } }
func setRead() { c := client.Get() var first bool = true var cursor []byte var total int64 = 0 t1 := time.Now().UnixNano() for string(cursor) != "" || first { ay, err := ledis.Values(c.Do("scan", cursor, "count", *count)) if err != nil { fmt.Printf("do scan err %s", err.Error()) return } else if len(ay) != 2 { fmt.Println("scan result invalid") return } cursor = ay[0].([]byte) data, err := ledis.Strings(ay[1], nil) if err != nil { fmt.Println(err) return } for _, k := range data { ledis.String(c.Do("get", []byte(k))) total++ if total%100000 == 0 { fmt.Println(total) fmt.Println(time.Now().Format("2006/01/02 15:04:05")) } } first = false } t2 := time.Now().UnixNano() delta := float64(t2-t1) / float64(time.Second) fmt.Printf("total %d kv keys , consumed %f seconds \n", total, delta) }
func waitZrangeBench(i int) { defer wg.Done() c := client.Get() defer c.Close() var start, stop int start = i * loop stop = i*loop + loop - 1 println(start, stop) ay, err := ledis.Values(c.Do("zrange", "myzset", start, stop)) if err != nil { fmt.Println("do zrange err %s", err.Error()) } for _, m := range ay { c.Do("zscore", "myzset", m.([]byte)) } }