func testListScan(t *testing.T, c *ledis.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, "lxscan") }
func testHashScan(t *testing.T, c *ledis.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, "hxscan") }
func testBitScan(t *testing.T, c *ledis.Client) { for i := 0; i < 10; i++ { if _, err := c.Do("bsetbit", fmt.Sprintf("%d", i), 1024, 1); err != nil { t.Fatal(err) } } checkScan(t, c, "bxscan") }
func sendSelect(client *ledis.Client, index int) { if index > 16 || index < 0 { index = 0 fmt.Println("index out of range, should less than 16") } _, err := client.Do("select", index) if err != nil { fmt.Printf("%s\n", err.Error()) } }
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) } }