...

Source file src/github.com/redis/go-redis/v9/doctests/cmds_servermgmt_test.go

Documentation: github.com/redis/go-redis/v9/doctests

     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  	// 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  
    53  func ExampleClient_cmd_info() {
    54  	ctx := context.Background()
    55  
    56  	rdb := redis.NewClient(&redis.Options{
    57  		Addr:     "localhost:6379",
    58  		Password: "", // no password docs
    59  		DB:       0,  // use default DB
    60  	})
    61  
    62  	// STEP_START info
    63  	infoResult, err := rdb.Info(ctx).Result()
    64  
    65  	if err != nil {
    66  		panic(err)
    67  	}
    68  
    69  	// Check the first 8 characters (the full info string contains
    70  	// much more text than this).
    71  	fmt.Println(infoResult[:8]) // >>> # Server
    72  	// STEP_END
    73  
    74  	// Output:
    75  	// # Server
    76  }
    77  

View as plain text