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") }
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") }
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") }
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) } }