forked from mirror/redis
docs: another ScanType example with "Hash" as the KeyType (#2212)
* docs: example ScanType call that passes in Hash and gets all keys * docs: added further example_scantype * docs: updated comment of ExampleClient_ScanType_Type_Hash
This commit is contained in:
parent
400ce60e74
commit
77dabc3019
|
@ -278,6 +278,36 @@ func ExampleClient_ScanType() {
|
|||
// Output: found 33 keys
|
||||
}
|
||||
|
||||
// ExampleClient_ScanType_Type_Hash uses the KeyType "hash"
|
||||
// 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++ {
|
||||
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\n
|
||||
}
|
||||
|
||||
// ExampleMapStringStringCmd_Scan shows how to scan the results of a map fetch
|
||||
// into a struct.
|
||||
func ExampleMapStringStringCmd_Scan() {
|
||||
|
|
Loading…
Reference in New Issue