Skip to content

Commit

Permalink
Add Scan example. Fixes redis#149.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Aug 19, 2015
1 parent 5a3d095 commit 37782ac
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,34 @@ func ExampleClient_Incr() {
// 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() {
var incr *redis.IntCmd
_, err := client.Pipelined(func(pipe *redis.Pipeline) error {
Expand Down

0 comments on commit 37782ac

Please sign in to comment.