Skip to content

Commit 9f9fa22

Browse files
DOC-4444 server management command examples (#3235)
1 parent 1b4abd6 commit 9f9fa22

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

doctests/cmds_servermgmt_test.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// EXAMPLE: cmds_servermgmt
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_cmd_flushall() {
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+
// STEP_START flushall
24+
// REMOVE_START
25+
rdb.Set(ctx, "testkey1", "1", 0)
26+
rdb.Set(ctx, "testkey2", "2", 0)
27+
rdb.Set(ctx, "testkey3", "3", 0)
28+
// REMOVE_END
29+
flushAllResult1, err := rdb.FlushAll(ctx).Result()
30+
31+
if err != nil {
32+
panic(err)
33+
}
34+
35+
fmt.Println(flushAllResult1) // >>> OK
36+
37+
flushAllResult2, err := rdb.Keys(ctx, "*").Result()
38+
39+
if err != nil {
40+
panic(err)
41+
}
42+
43+
fmt.Println(flushAllResult2) // >>> []
44+
// STEP_END
45+
46+
// Output:
47+
// OK
48+
// []
49+
}
50+
51+
func ExampleClient_cmd_info() {
52+
ctx := context.Background()
53+
54+
rdb := redis.NewClient(&redis.Options{
55+
Addr: "localhost:6379",
56+
Password: "", // no password docs
57+
DB: 0, // use default DB
58+
})
59+
60+
// STEP_START info
61+
infoResult, err := rdb.Info(ctx).Result()
62+
63+
if err != nil {
64+
panic(err)
65+
}
66+
67+
// Check the first 8 characters (the full info string contains
68+
// much more text than this).
69+
fmt.Println(infoResult[:8]) // >>> # Server
70+
// STEP_END
71+
72+
// Output:
73+
// # Server
74+
}

0 commit comments

Comments
 (0)