From 37782aca57a983ce94dd1d70fdca32af956120a7 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 19 Aug 2015 11:44:46 +0300 Subject: [PATCH] Add Scan example. Fixes #149. --- example_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/example_test.go b/example_test.go index de9f8da..58b7dfe 100644 --- a/example_test.go +++ b/example_test.go @@ -109,6 +109,34 @@ func ExampleClient_Incr() { // Output: 1 } +func ExampleClient_Scan() { + client.FlushDb() + for i := 0; i < 33; i++ { + err := client.Set(fmt.Sprintf("key%d", i), "value", 0).Err() + if err != nil { + panic(err) + } + } + + var cursor int64 + var n int + for { + var keys []string + var err error + cursor, keys, err = client.Scan(cursor, "", 10).Result() + if err != nil { + panic(err) + } + n += len(keys) + if cursor == 0 { + break + } + } + + fmt.Printf("found %d keys\n", n) + // Output: found 33 keys +} + func ExampleClient_Pipelined() { var incr *redis.IntCmd _, err := client.Pipelined(func(pipe *redis.Pipeline) error {