MCPcopy
hub / github.com/redis/go-redis / ExampleClient_Scan

Function ExampleClient_Scan

example_test.go:262–288  ·  example_test.go::ExampleClient_Scan
()

Source from the content-addressed store, hash-verified

260}
261
262func ExampleClient_Scan() {
263 rdb.FlushDB(ctx)
264 for i := 0; i < 33; i++ {
265 err := rdb.Set(ctx, fmt.Sprintf("key%d", i), "value", 0).Err()
266 if err != nil {
267 panic(err)
268 }
269 }
270
271 var cursor uint64
272 var n int
273 for {
274 var keys []string
275 var err error
276 keys, cursor, err = rdb.Scan(ctx, cursor, "key*", 10).Result()
277 if err != nil {
278 panic(err)
279 }
280 n += len(keys)
281 if cursor == 0 {
282 break
283 }
284 }
285
286 fmt.Printf("found %d keys\n", n)
287 // Output: found 33 keys
288}
289
290func ExampleClient_ScanType() {
291 rdb.FlushDB(ctx)

Callers

nothing calls this directly

Calls 6

FlushDBMethod · 0.65
ErrMethod · 0.65
SetMethod · 0.65
ResultMethod · 0.65
ScanMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected