Merge pull request #150 from go-redis/feature/scan-example

Add Scan example. Fixes #149.
This commit is contained in:
Vladimir Mihailenco 2015-08-19 12:29:36 +03:00
commit 391c319c78
1 changed files with 28 additions and 0 deletions

View File

@ -109,6 +109,34 @@ func ExampleClient_Incr() {
// Output: 1 <nil> // Output: 1 <nil>
} }
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() { func ExampleClient_Pipelined() {
var incr *redis.IntCmd var incr *redis.IntCmd
_, err := client.Pipelined(func(pipe *redis.Pipeline) error { _, err := client.Pipelined(func(pipe *redis.Pipeline) error {