Skip to content

Commit e5837c9

Browse files
authored
Merge branch 'master' into DOC-4233-geospatial-tces
2 parents 5e60f16 + bef6b10 commit e5837c9

File tree

5 files changed

+388
-0
lines changed

5 files changed

+388
-0
lines changed

doctests/bitfield_tutorial_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// EXAMPLE: bitfield_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_bf() {
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, "bike:1:stats")
25+
// REMOVE_END
26+
27+
// STEP_START bf
28+
res1, err := rdb.BitField(ctx, "bike:1:stats",
29+
"set", "u32", "#0", "1000",
30+
).Result()
31+
32+
if err != nil {
33+
panic(err)
34+
}
35+
36+
fmt.Println(res1) // >>> [0]
37+
38+
res2, err := rdb.BitField(ctx,
39+
"bike:1:stats",
40+
"incrby", "u32", "#0", "-50",
41+
"incrby", "u32", "#1", "1",
42+
).Result()
43+
44+
if err != nil {
45+
panic(err)
46+
}
47+
48+
fmt.Println(res2) // >>> [950 1]
49+
50+
res3, err := rdb.BitField(ctx,
51+
"bike:1:stats",
52+
"incrby", "u32", "#0", "500",
53+
"incrby", "u32", "#1", "1",
54+
).Result()
55+
56+
if err != nil {
57+
panic(err)
58+
}
59+
60+
fmt.Println(res3) // >>> [1450 2]
61+
62+
res4, err := rdb.BitField(ctx, "bike:1:stats",
63+
"get", "u32", "#0",
64+
"get", "u32", "#1",
65+
).Result()
66+
67+
if err != nil {
68+
panic(err)
69+
}
70+
71+
fmt.Println(res4) // >>> [1450 2]
72+
// STEP_END
73+
74+
// Output:
75+
// [0]
76+
// [950 1]
77+
// [1450 2]
78+
// [1450 2]
79+
}

doctests/cms_tutorial_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// EXAMPLE: cms_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_cms() {
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:profit")
25+
// REMOVE_END
26+
27+
// STEP_START cms
28+
res1, err := rdb.CMSInitByProb(ctx, "bikes:profit", 0.001, 0.002).Result()
29+
30+
if err != nil {
31+
panic(err)
32+
}
33+
34+
fmt.Println(res1) // >>> OK
35+
36+
res2, err := rdb.CMSIncrBy(ctx, "bikes:profit",
37+
"Smoky Mountain Striker", 100,
38+
).Result()
39+
40+
if err != nil {
41+
panic(err)
42+
}
43+
44+
fmt.Println(res2) // >>> [100]
45+
46+
res3, err := rdb.CMSIncrBy(ctx, "bikes:profit",
47+
"Rocky Mountain Racer", 200,
48+
"Cloudy City Cruiser", 150,
49+
).Result()
50+
51+
if err != nil {
52+
panic(err)
53+
}
54+
55+
fmt.Println(res3) // >>> [200 150]
56+
57+
res4, err := rdb.CMSQuery(ctx, "bikes:profit",
58+
"Smoky Mountain Striker",
59+
).Result()
60+
61+
if err != nil {
62+
panic(err)
63+
}
64+
65+
fmt.Println(res4) // >>> [100]
66+
67+
res5, err := rdb.CMSInfo(ctx, "bikes:profit").Result()
68+
69+
if err != nil {
70+
panic(err)
71+
}
72+
73+
fmt.Printf("Width: %v, Depth: %v, Count: %v",
74+
res5.Width, res5.Depth, res5.Count)
75+
// >>> Width: 2000, Depth: 9, Count: 450
76+
// STEP_END
77+
78+
// Output:
79+
// OK
80+
// [100]
81+
// [200 150]
82+
// [100]
83+
// Width: 2000, Depth: 9, Count: 450
84+
}

doctests/cuckoo_tutorial_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// EXAMPLE: cuckoo_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_cuckoo() {
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 cuckoo
28+
res1, err := rdb.CFReserve(ctx, "bikes:models", 1000000).Result()
29+
30+
if err != nil {
31+
panic(err)
32+
}
33+
34+
fmt.Println(res1) // >>> OK
35+
36+
res2, err := rdb.CFAdd(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.CFExists(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.CFExists(ctx, "bikes:models", "Terrible Bike Name").Result()
53+
54+
if err != nil {
55+
panic(err)
56+
}
57+
58+
fmt.Println(res4) // >>> false
59+
60+
res5, err := rdb.CFDel(ctx, "bikes:models", "Smoky Mountain Striker").Result()
61+
62+
if err != nil {
63+
panic(err)
64+
}
65+
66+
fmt.Println(res5) // >>> true
67+
// STEP_END
68+
69+
// Output:
70+
// OK
71+
// true
72+
// true
73+
// false
74+
// true
75+
}

doctests/hll_tutorial_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// EXAMPLE: hll_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_pfadd() {
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", "commuter_bikes", "all_bikes")
25+
// REMOVE_END
26+
27+
// STEP_START pfadd
28+
res1, err := rdb.PFAdd(ctx, "bikes", "Hyperion", "Deimos", "Phoebe", "Quaoar").Result()
29+
30+
if err != nil {
31+
panic(err)
32+
}
33+
34+
fmt.Println(res1) // 1
35+
36+
res2, err := rdb.PFCount(ctx, "bikes").Result()
37+
38+
if err != nil {
39+
panic(err)
40+
}
41+
42+
fmt.Println(res2) // 4
43+
44+
res3, err := rdb.PFAdd(ctx, "commuter_bikes", "Salacia", "Mimas", "Quaoar").Result()
45+
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
fmt.Println(res3) // 1
51+
52+
res4, err := rdb.PFMerge(ctx, "all_bikes", "bikes", "commuter_bikes").Result()
53+
54+
if err != nil {
55+
panic(err)
56+
}
57+
58+
fmt.Println(res4) // OK
59+
60+
res5, err := rdb.PFCount(ctx, "all_bikes").Result()
61+
62+
if err != nil {
63+
panic(err)
64+
}
65+
66+
fmt.Println(res5) // 6
67+
// STEP_END
68+
69+
// Output:
70+
// 1
71+
// 4
72+
// 1
73+
// OK
74+
// 6
75+
}

doctests/topk_tutorial_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// EXAMPLE: topk_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_topk() {
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:keywords")
25+
// REMOVE_END
26+
27+
// STEP_START topk
28+
res1, err := rdb.TopKReserve(ctx, "bikes:keywords", 5).Result()
29+
30+
if err != nil {
31+
panic(err)
32+
}
33+
34+
fmt.Println(res1) // >>> OK
35+
36+
res2, err := rdb.TopKAdd(ctx, "bikes:keywords",
37+
"store",
38+
"seat",
39+
"handlebars",
40+
"handles",
41+
"pedals",
42+
"tires",
43+
"store",
44+
"seat",
45+
).Result()
46+
47+
if err != nil {
48+
panic(err)
49+
}
50+
51+
fmt.Println(res2) // >>> [ handlebars ]
52+
53+
res3, err := rdb.TopKList(ctx, "bikes:keywords").Result()
54+
55+
if err != nil {
56+
panic(err)
57+
}
58+
59+
fmt.Println(res3) // [store seat pedals tires handles]
60+
61+
res4, err := rdb.TopKQuery(ctx, "bikes:keywords", "store", "handlebars").Result()
62+
63+
if err != nil {
64+
panic(err)
65+
}
66+
67+
fmt.Println(res4) // [true false]
68+
// STEP_END
69+
70+
// Output:
71+
// OK
72+
// [ handlebars ]
73+
// [store seat pedals tires handles]
74+
// [true false]
75+
}

0 commit comments

Comments
 (0)