MCPcopy
hub / github.com/redis/go-redis / ExampleClient_cmd_flushall

Function ExampleClient_cmd_flushall

doctests/cmds_servermgmt_test.go:14–51  ·  view source on GitHub ↗

HIDE_END

()

Source from the content-addressed store, hash-verified

12// HIDE_END
13
14func 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 // make sure we are working with fresh database
26 rdb.FlushDB(ctx)
27 rdb.Set(ctx, "testkey1", "1", 0)
28 rdb.Set(ctx, "testkey2", "2", 0)
29 rdb.Set(ctx, "testkey3", "3", 0)
30 // REMOVE_END
31 flushAllResult1, err := rdb.FlushAll(ctx).Result()
32
33 if err != nil {
34 panic(err)
35 }
36
37 fmt.Println(flushAllResult1) // >>> OK
38
39 flushAllResult2, err := rdb.Keys(ctx, "*").Result()
40
41 if err != nil {
42 panic(err)
43 }
44
45 fmt.Println(flushAllResult2) // >>> []
46 // STEP_END
47
48 // Output:
49 // OK
50 // []
51}
52
53func ExampleClient_cmd_info() {
54 ctx := context.Background()

Callers

nothing calls this directly

Calls 5

FlushDBMethod · 0.65
SetMethod · 0.65
ResultMethod · 0.65
FlushAllMethod · 0.65
KeysMethod · 0.65

Tested by

no test coverage detected