example/disable-maintnotifications/README.md
This example demonstrates how to use the go-redis client with maintenance notifications disabled.
Maintenance notifications are a Redis Cloud feature that allows the server to notify clients about:
The go-redis client supports three modes:
ModeDisabled: Client doesn't send CLIENT MAINT_NOTIFICATIONS ON commandModeEnabled: Client forcefully sends the command, interrupts connection on errorModeAuto (default): Client tries to send the command, disables feature on errorYou should disable maintenance notifications when:
import (
"github.com/redis/go-redis/v9"
"github.com/redis/go-redis/v9/maintnotifications"
)
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
// Explicitly disable maintenance notifications
MaintNotificationsConfig: &maintnotifications.Config{
Mode: maintnotifications.ModeDisabled,
},
})
defer rdb.Close()
rdbCluster := redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{"localhost:7000", "localhost:7001", "localhost:7002"},
// Disable maintenance notifications for cluster
MaintNotificationsConfig: &maintnotifications.Config{
Mode: maintnotifications.ModeDisabled,
},
})
defer rdbCluster.Close()
If you don't specify MaintNotifications, the client defaults to ModeAuto:
// This uses ModeAuto by default
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
// MaintNotificationsConfig: nil means ModeAuto
})
With ModeAuto, the client will:
Start a Redis server:
redis-server --port 6379
Run the example:
go run main.go
=== Example 1: Explicitly Disabled ===
✓ Connected successfully (maintenance notifications disabled)
✓ SET operation successful
✓ GET operation successful: value1
=== Example 2: Default Behavior (ModeAuto) ===
✓ Connected successfully (maintenance notifications auto-enabled)
=== Example 3: Cluster Client with Disabled Notifications ===
Cluster not available (expected): ...
=== Example 4: Performance Comparison ===
✓ 1000 SET operations (disabled): 45ms
✓ 1000 SET operations (auto): 46ms
=== Cleanup ===
✓ Database flushed
=== Summary ===
Maintenance notifications can be disabled by setting:
MaintNotificationsConfig: &maintnotifications.Config{
Mode: maintnotifications.ModeDisabled,
}
This is useful when:
- Connecting to non-Redis Cloud instances
- You want to handle failovers manually
- You want to minimize client-side overhead
- The Redis server doesn't support CLIENT MAINT_NOTIFICATIONS
Disabling maintenance notifications has minimal performance impact. The main differences are:
CLIENT MAINT_NOTIFICATIONS ON) during connection initializationIn most cases, the performance difference is negligible (< 1%).