Skip to content

Commit e99abe4

Browse files
DOC-4237 added Bloom filter examples (redis#3115)
Co-authored-by: Vladyslav Vildanov <[email protected]>
1 parent 9e79c9b commit e99abe4

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

Diff for: doctests/bf_tutorial_test.go

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// EXAMPLE: bf_tutorial
2+
// HIDE_START
3+
package example_commands_test
4+
5+
import (
6+
"context"
7+
"fmt"
8+
9+
"github.com/redis/go-redis/v9"
10+
)
11+
12+
// HIDE_END
13+
14+
func ExampleClient_bloom() {
15+
ctx := context.Background()
16+
17+
rdb := redis.NewClient(&redis.Options{
18+
Addr: "localhost:6379",
19+
Password: "", // no password docs
20+
DB: 0, // use default DB
21+
})
22+
23+
// REMOVE_START
24+
rdb.Del(ctx, "bikes:models")
25+
// REMOVE_END
26+
27+
// STEP_START bloom
28+
res1, err := rdb.BFReserve(ctx, "bikes:models", 0.01, 1000).Result()
29+
30+
if err != nil {
31+
panic(err)
32+
}
33+
34+
fmt.Println(res1) // >>> OK
35+
36+
res2, err := rdb.BFAdd(ctx, "bikes:models", "Smoky Mountain Striker").Result()
37+
38+
if err != nil {
39+
panic(err)
40+
}
41+
42+
fmt.Println(res2) // >>> true
43+
44+
res3, err := rdb.BFExists(ctx, "bikes:models", "Smoky Mountain Striker").Result()
45+
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
fmt.Println(res3) // >>> true
51+
52+
res4, err := rdb.BFMAdd(ctx, "bikes:models",
53+
"Rocky Mountain Racer",
54+
"Cloudy City Cruiser",
55+
"Windy City Wippet",
56+
).Result()
57+
58+
if err != nil {
59+
panic(err)
60+
}
61+
62+
fmt.Println(res4) // >>> [true true true]
63+
64+
res5, err := rdb.BFMExists(ctx, "bikes:models",
65+
"Rocky Mountain Racer",
66+
"Cloudy City Cruiser",
67+
"Windy City Wippet",
68+
).Result()
69+
70+
if err != nil {
71+
panic(err)
72+
}
73+
74+
fmt.Println(res5) // >>> [true true true]
75+
// STEP_END
76+
77+
// Output:
78+
// OK
79+
// true
80+
// true
81+
// [true true true]
82+
// [true true true]
83+
}

0 commit comments

Comments
 (0)