예제 #1
0
func TestCmdEval(t *testing.T) {
	c := getTestConn()
	defer c.Close()

	if v, err := goredis.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 := goredis.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 = goredis.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 := goredis.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 := goredis.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 := goredis.String(c.Do("script", "flush")); err != nil {
		t.Fatal(err)
	} else if ok != "OK" {
		t.Fatal(ok)
	}

	if ay, err := goredis.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))
	}
}
예제 #2
0
func checkScan(t *testing.T, c *goredis.Client, tp string) {
	if ay, err := goredis.Values(c.Do("XSCAN", tp, "", "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 := goredis.Values(c.Do("XSCAN", tp, "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)
	}

}
예제 #3
0
func TestHashScan(t *testing.T) {
	c := getTestConn()
	defer c.Close()

	key := "scan_hash"
	c.Do("HMSET", key, "a", 1, "b", 2)

	if ay, err := goredis.Values(c.Do("XHSCAN", key, "")); err != nil {
		t.Fatal(err)
	} else if len(ay) != 2 {
		t.Fatal(len(ay))
	} else {
		checkScanValues(t, ay[1], "a", 1, "b", 2)
	}
}
예제 #4
0
func TestZSetScan(t *testing.T) {
	c := getTestConn()
	defer c.Close()

	key := "scan_zset"
	c.Do("ZADD", key, 1, "a", 2, "b")

	if ay, err := goredis.Values(c.Do("XZSCAN", key, "")); err != nil {
		t.Fatal(err)
	} else if len(ay) != 2 {
		t.Fatal(len(ay))
	} else {
		checkScanValues(t, ay[1], "a", 1, "b", 2)
	}

}