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

Function main

example/disable-maintnotifications/main.go:12–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func main() {
13 ctx := context.Background()
14
15 // Example 0: Explicitly disable maintenance notifications
16 fmt.Println("=== Example 0: Explicitly Enabled ===")
17 rdb0 := redis.NewClient(&redis.Options{
18 Addr: "localhost:6379",
19
20 // Explicitly disable maintenance notifications
21 // This prevents the client from sending CLIENT MAINT_NOTIFICATIONS ON
22 MaintNotificationsConfig: &maintnotifications.Config{
23 Mode: maintnotifications.ModeEnabled,
24 },
25 })
26 defer rdb0.Close()
27
28 // Test the connection
29 if err := rdb0.Ping(ctx).Err(); err != nil {
30 fmt.Printf("Failed to connect: %v\n\n", err)
31 }
32 fmt.Println("When ModeEnabled, the client will return an error if the server doesn't support maintenance notifications.")
33 fmt.Printf("ModeAuto will silently disable the feature.\n\n")
34
35 // Example 1: Explicitly disable maintenance notifications
36 fmt.Println("=== Example 1: Explicitly Disabled ===")
37 rdb1 := redis.NewClient(&redis.Options{
38 Addr: "localhost:6379",
39
40 // Explicitly disable maintenance notifications
41 // This prevents the client from sending CLIENT MAINT_NOTIFICATIONS ON
42 MaintNotificationsConfig: &maintnotifications.Config{
43 Mode: maintnotifications.ModeDisabled,
44 },
45 })
46 defer rdb1.Close()
47
48 // Test the connection
49 if err := rdb1.Ping(ctx).Err(); err != nil {
50 fmt.Printf("Failed to connect: %v\n\n", err)
51 return
52 }
53 fmt.Println("✓ Connected successfully (maintenance notifications disabled)")
54
55 // Perform some operations
56 if err := rdb1.Set(ctx, "example:key1", "value1", 0).Err(); err != nil {
57 fmt.Printf("Failed to set key: %v\n\n", err)
58 return
59 }
60 fmt.Println("✓ SET operation successful")
61
62 val, err := rdb1.Get(ctx, "example:key1").Result()
63 if err != nil {
64 fmt.Printf("Failed to get key: %v\n\n", err)
65 return
66 }
67 fmt.Printf("✓ GET operation successful: %s\n\n", val)
68
69 // Example 2: Using nil config (defaults to ModeAuto)

Callers

nothing calls this directly

Calls 9

PoolStatsMethod · 0.95
CloseMethod · 0.65
ErrMethod · 0.65
PingMethod · 0.65
PrintfMethod · 0.65
SetMethod · 0.65
ResultMethod · 0.65
GetMethod · 0.65
FlushDBMethod · 0.65

Tested by

no test coverage detected