Example #1
0
func main() {
	c, err := cluster.New("localhost:7000")
	if err != nil {
		log.Fatal(err)
	}

	oldKeys := make(chan string, 1000)

	doRand := time.Tick(100 * time.Millisecond)
	doOldRand := time.Tick(1 * time.Second)

	for {
		select {
		case <-doRand:
			key := randString()
			doGetSet(c, key)
			select {
			case oldKeys <- key:
			default:
			}

		case <-doOldRand:
			select {
			case key := <-oldKeys:
				doGetSet(c, key)
			default:
			}
		}
	}
}
Example #2
0
// Similar to TestScan, but scans over a whole cluster
func TestClusterScan(t *T) {
	cluster, err := cluster.New("127.0.0.1:7000")
	require.Nil(t, err)

	prefix := "scanTestPrefix"

	fullMap := map[string]bool{}
	for i := 0; i < 100; i++ {
		key := prefix + ":" + strconv.Itoa(i)
		fullMap[key] = true
		require.Nil(t, cluster.Cmd("SET", key, "1").Err)
	}

	// make sure we get all results when scanning with an existing prefix
	ch := make(chan string)
	go func() {
		err = Scan(cluster, ch, "SCAN", "", prefix+":*")
	}()
	testMap := map[string]bool{}
	for key := range ch {
		testMap[key] = true
	}
	require.Nil(t, err)
	assert.Equal(t, fullMap, testMap)

	// make sure we don't get any results when scanning with a non-existing
	// prefix
	ch = make(chan string)
	go func() {
		err = Scan(cluster, ch, "SCAN", "", prefix+"DNE:*")
	}()
	testMap = map[string]bool{}
	for key := range ch {
		testMap[key] = true
	}
	require.Nil(t, err)
	assert.Equal(t, map[string]bool{}, testMap)
}