From 3046cfae337b2ca5e075d95c4605a38e01695ad0 Mon Sep 17 00:00:00 2001 From: rustymagnet3000 <5367141+rustymagnet3000@users.noreply.github.com> Date: Fri, 16 Sep 2022 10:32:43 +0100 Subject: [PATCH 1/3] docs: example ScanType call that passes in Hash and gets all keys --- example_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/example_test.go b/example_test.go index 56cf9018f3..f20674c3b1 100644 --- a/example_test.go +++ b/example_test.go @@ -278,6 +278,36 @@ func ExampleClient_ScanType() { // Output: found 33 keys } +// ExampleClient_ScanType_Type_Hash uses the KeyType "hash" +// useful to see how you could get loop through lots of "keys" in Redis and get a []string of all the keys +func ExampleClient_ScanType_Type_Hash() { + rdb.FlushDB(ctx) + for i := 0; i < 33; i++ { + err := rdb.HSet(context.TODO(), fmt.Sprintf("key%d", i), "value", "foo").Err() + if err != nil { + panic(err) + } + } + + var allKeys []string + var cursor uint64 + var err error + + for { + var keysFromScan []string + keysFromScan, cursor, err = rdb.ScanType(context.TODO(), cursor, "key*", 10, "hash").Result() + if err != nil { + panic(err) + } + allKeys = append(allKeys, keysFromScan...) + if cursor == 0 { + break + } + } + fmt.Printf("%d keys ready for use\n", len(allKeys)) + // Output: 33 keys ready for use +} + // ExampleMapStringStringCmd_Scan shows how to scan the results of a map fetch // into a struct. func ExampleMapStringStringCmd_Scan() { From 55ef8399ce84105d585a4f273423f6e0c49d1348 Mon Sep 17 00:00:00 2001 From: rustymagnet3000 <5367141+rustymagnet3000@users.noreply.github.com> Date: Fri, 16 Sep 2022 11:01:10 +0100 Subject: [PATCH 2/3] docs: added further example_scantype --- example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example_test.go b/example_test.go index f20674c3b1..036987e14d 100644 --- a/example_test.go +++ b/example_test.go @@ -305,7 +305,7 @@ func ExampleClient_ScanType_Type_Hash() { } } fmt.Printf("%d keys ready for use\n", len(allKeys)) - // Output: 33 keys ready for use + // Output: 33 keys ready for use\n } // ExampleMapStringStringCmd_Scan shows how to scan the results of a map fetch From c1549071089474d11317627d137e685a8585d8d5 Mon Sep 17 00:00:00 2001 From: rustymagnet3000 <5367141+rustymagnet3000@users.noreply.github.com> Date: Fri, 16 Sep 2022 14:56:03 +0100 Subject: [PATCH 3/3] docs: updated comment of ExampleClient_ScanType_Type_Hash --- example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example_test.go b/example_test.go index 036987e14d..2626b9aa64 100644 --- a/example_test.go +++ b/example_test.go @@ -279,7 +279,7 @@ func ExampleClient_ScanType() { } // ExampleClient_ScanType_Type_Hash uses the KeyType "hash" -// useful to see how you could get loop through lots of "keys" in Redis and get a []string of all the keys +// Uses ScanType toZZ loop through lots of "keys" in Redis, 10 at a time, and add each key to a []string func ExampleClient_ScanType_Type_Hash() { rdb.FlushDB(ctx) for i := 0; i < 33; i++ {