Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ runs:
- name: Setup Test environment
env:
REDIS_VERSION: ${{ inputs.redis-version }}
CLIENT_LIBS_TEST_IMAGE: "redislabs/client-libs-test:${{ inputs.redis-version }}"
run: |
set -e
redis_version_np=$(echo "$REDIS_VERSION" | grep -oP '^\d+.\d+')

# Mapping of redis version to redis testing containers
declare -A redis_version_mapping=(
["8.4.x"]="8.4-RC1-pre"
["8.2.x"]="8.2.1-pre"
["8.0.x"]="8.0.2"
["7.4.x"]="rs-7.4.0-v5"
["7.2.x"]="rs-7.2.0-v17"
)

if [[ -v redis_version_mapping[$REDIS_VERSION] ]]; then
echo "REDIS_VERSION=${redis_version_np}" >> $GITHUB_ENV
echo "REDIS_IMAGE=redis:${{ inputs.redis-version }}" >> $GITHUB_ENV
echo "REDIS_IMAGE=redis:${REDIS_VERSION}" >> $GITHUB_ENV
echo "CLIENT_LIBS_TEST_IMAGE=redislabs/client-libs-test:${redis_version_mapping[$REDIS_VERSION]}" >> $GITHUB_ENV
else
echo "Version not found in the mapping."
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Go

on:
push:
branches: [master, v9, v9.7, v9.8, 'ndyakov/*', 'ofekshenawa/*', 'htemelski-redis/*', 'ce/*']
branches: [master, v9, 'v9.*']
pull_request:
branches: [master, v9, v9.7, v9.8, 'ndyakov/*', 'ofekshenawa/*', 'htemelski-redis/*', 'ce/*']

Expand All @@ -18,9 +18,9 @@ jobs:
fail-fast: false
matrix:
redis-version:
- "8.4.x" # Redis CE 8.4
- "8.2.x" # Redis CE 8.2
- "8.0.x" # Redis CE 8.0
- "7.4.x" # Redis stack 7.4
go-version:
- "1.23.x"
- "1.24.x"
Expand All @@ -44,9 +44,9 @@ jobs:

# Mapping of redis version to redis testing containers
declare -A redis_version_mapping=(
["8.4.x"]="8.4-RC1-pre"
["8.2.x"]="8.2.1-pre"
["8.0.x"]="8.0.2"
["7.4.x"]="rs-7.4.0-v5"
)
if [[ -v redis_version_mapping[$REDIS_VERSION] ]]; then
echo "REDIS_VERSION=${redis_version_np}" >> $GITHUB_ENV
Expand Down Expand Up @@ -74,10 +74,9 @@ jobs:
fail-fast: false
matrix:
redis-version:
- "8.4.x" # Redis CE 8.4
- "8.2.x" # Redis CE 8.2
- "8.0.x" # Redis CE 8.0
- "7.4.x" # Redis stack 7.4
- "7.2.x" # Redis stack 7.2
go-version:
- "1.23.x"
- "1.24.x"
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
REDIS_VERSION ?= 8.2
REDIS_VERSION ?= 8.4
RE_CLUSTER ?= false
RCE_DOCKER ?= true
CLIENT_LIBS_TEST_IMAGE ?= redislabs/client-libs-test:8.2.1-pre
CLIENT_LIBS_TEST_IMAGE ?= redislabs/client-libs-test:8.4-RC1-pre

docker.start:
export RE_CLUSTER=$(RE_CLUSTER) && \
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

services:
redis:
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.2.1-pre}
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4-RC1-pre}
platform: linux/amd64
container_name: redis-standalone
environment:
Expand All @@ -23,7 +23,7 @@ services:
- all

osscluster:
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.2.1-pre}
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4-RC1-pre}
platform: linux/amd64
container_name: redis-osscluster
environment:
Expand All @@ -40,7 +40,7 @@ services:
- all

sentinel-cluster:
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.2.1-pre}
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4-RC1-pre}
platform: linux/amd64
container_name: redis-sentinel-cluster
network_mode: "host"
Expand All @@ -60,7 +60,7 @@ services:
- all

sentinel:
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.2.1-pre}
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4-RC1-pre}
platform: linux/amd64
container_name: redis-sentinel
depends_on:
Expand All @@ -84,7 +84,7 @@ services:
- all

ring-cluster:
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.2.1-pre}
image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4-RC1-pre}
platform: linux/amd64
container_name: redis-ring-cluster
environment:
Expand Down
133 changes: 133 additions & 0 deletions example/disable-maintnotifications/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Disable Maintenance Notifications Example

This example demonstrates how to use the go-redis client with maintenance notifications **disabled**.

## What are Maintenance Notifications?

Maintenance notifications are a Redis Cloud feature that allows the server to notify clients about:
- Planned maintenance events
- Failover operations
- Node migrations
- Cluster topology changes

The go-redis client supports three modes:
- **`ModeDisabled`**: Client doesn't send `CLIENT MAINT_NOTIFICATIONS ON` command
- **`ModeEnabled`**: Client forcefully sends the command, interrupts connection on error
- **`ModeAuto`** (default): Client tries to send the command, disables feature on error

## When to Disable Maintenance Notifications

You should disable maintenance notifications when:

1. **Connecting to non-Redis Cloud / Redis Enterprise instances** - Standard Redis servers don't support this feature
2. **You want to handle failovers manually** - Your application has custom failover logic
3. **Minimizing client-side overhead** - You want the simplest possible client behavior
4. **The Redis server doesn't support the feature** - Older Redis versions or forks

## Usage

### Basic Example

```go
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()
```

### Cluster Client Example

```go
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()
```

### Default Behavior (ModeAuto)

If you don't specify `MaintNotifications`, the client defaults to `ModeAuto`:

```go
// This uses ModeAuto by default
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
// MaintNotificationsConfig: nil means ModeAuto
})
```

With `ModeAuto`, the client will:
1. Try to enable maintenance notifications
2. If the server doesn't support it, silently disable the feature
3. Continue normal operation

## Running the Example

1. Start a Redis server:
```bash
redis-server --port 6379
```

2. Run the example:
```bash
go run main.go
```

## Expected Output

```
=== 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
```

## Performance Impact

Disabling maintenance notifications has minimal performance impact. The main differences are:

1. **Connection Setup**: One less command (`CLIENT MAINT_NOTIFICATIONS ON`) during connection initialization
2. **Runtime Overhead**: No background processing of maintenance notifications
3. **Memory Usage**: Slightly lower memory footprint (no notification handlers)

In most cases, the performance difference is negligible (< 1%).
12 changes: 12 additions & 0 deletions example/disable-maintnotifications/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/redis/go-redis/example/disable-maintnotifications

go 1.23

replace github.com/redis/go-redis/v9 => ../..

require github.com/redis/go-redis/v9 v9.7.0

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
)
8 changes: 8 additions & 0 deletions example/disable-maintnotifications/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
Loading
Loading