Example #1
0
func testListKeyScan(t *testing.T, c *goredis.Client) {
	for i := 0; i < 10; i++ {
		if _, err := c.Do("lpush", fmt.Sprintf("%d", i), fmt.Sprintf("%d", i)); err != nil {
			t.Fatal(err)
		}
	}

	checkScan(t, c, "LIST")
}
Example #2
0
func testHashKeyScan(t *testing.T, c *goredis.Client) {
	for i := 0; i < 10; i++ {
		if _, err := c.Do("hset", fmt.Sprintf("%d", i), fmt.Sprintf("%d", i), []byte("value")); err != nil {
			t.Fatal(err)
		}
	}

	checkScan(t, c, "HASH")
}
Example #3
0
func testZSetKeyScan(t *testing.T, c *goredis.Client) {
	for i := 0; i < 10; i++ {
		if _, err := c.Do("zadd", fmt.Sprintf("%d", i), i, []byte("value")); err != nil {
			t.Fatal(err)
		}
	}

	checkScan(t, c, "ZSET")
}
Example #4
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)
	}

}