Skip to content

Commit

Permalink
fix: drop to 3 nodes, respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
df-wg committed Jan 22, 2025
1 parent 1b0fb41 commit fbe58fc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 53 deletions.
43 changes: 1 addition & 42 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ services:
profiles:
- dev

# 3 node minimum for a cluster, per redis documentation
redis-cluster-node-0:
image: redis:${DC_REDIS_VERSION:-7.2.4}-alpine
command: redis-server /usr/local/etc/redis/redis.conf
Expand Down Expand Up @@ -279,42 +280,6 @@ services:
profiles:
- dev

redis-cluster-node-3:
image: redis:${DC_REDIS_VERSION:-7.2.4}-alpine
command: redis-server /usr/local/etc/redis/redis.conf
networks:
- primary
ports:
- "7003:6379"
volumes:
- ./docker/redis/redis-cluster.conf:/usr/local/etc/redis/redis.conf
profiles:
- dev

redis-cluster-node-4:
image: redis:${DC_REDIS_VERSION:-7.2.4}-alpine
command: redis-server /usr/local/etc/redis/redis.conf
networks:
- primary
ports:
- "7004:6379"
volumes:
- ./docker/redis/redis-cluster.conf:/usr/local/etc/redis/redis.conf
profiles:
- dev

redis-cluster-node-5:
image: redis:${DC_REDIS_VERSION:-7.2.4}-alpine
command: redis-server /usr/local/etc/redis/redis.conf
networks:
- primary
ports:
- "7005:6379"
volumes:
- ./docker/redis/redis-cluster.conf:/usr/local/etc/redis/redis.conf
profiles:
- dev

redis-cluster-configure:
image: redis:${DC_REDIS_VERSION:-7.2.4}-alpine
command: /usr/local/etc/redis/redis-cluster-create.sh
Expand All @@ -324,9 +289,6 @@ services:
- redis-cluster-node-0
- redis-cluster-node-1
- redis-cluster-node-2
- redis-cluster-node-3
- redis-cluster-node-4
- redis-cluster-node-5
volumes:
- ./docker/redis/:/usr/local/etc/redis/

Expand Down Expand Up @@ -370,6 +332,3 @@ volumes:
redis-cluster-node-0:
redis-cluster-node-1:
redis-cluster-node-2:
redis-cluster-node-3:
redis-cluster-node-4:
redis-cluster-node-5:
8 changes: 1 addition & 7 deletions docker/redis/redis-cluster-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ sleep 10
node_0_ip=$(getent hosts redis-cluster-node-0 | awk '{ print $1 }')
node_1_ip=$(getent hosts redis-cluster-node-1 | awk '{ print $1 }')
node_2_ip=$(getent hosts redis-cluster-node-2 | awk '{ print $1 }')
node_3_ip=$(getent hosts redis-cluster-node-3 | awk '{ print $1 }')
node_4_ip=$(getent hosts redis-cluster-node-4 | awk '{ print $1 }')
node_5_ip=$(getent hosts redis-cluster-node-5 | awk '{ print $1 }')


redis-cli --cluster create \
$node_0_ip:6379 \
$node_1_ip:6379 \
$node_2_ip:6379 \
$node_3_ip:6379 \
$node_4_ip:6379 \
$node_5_ip:6379 \
--cluster-replicas 1 --cluster-yes
--cluster-replicas 0 --cluster-yes
2 changes: 1 addition & 1 deletion docker/redis/redis-cluster.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
bind 0.0.0.0
protected-mode n
protected-mode no
maxmemory 100mb
maxmemory-policy noeviction
save 60 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"fmt"
"github.com/redis/go-redis/v9"
"go.uber.org/zap"
"io"
"strings"
)

// RDCloser is an interface that combines the redis.Cmdable and io.Closer interfaces, ensuring that we can close the
// client connection.
type RDCloser interface {
redis.Cmdable
Close() error
io.Closer
}

type RedisCloserOptions struct {
Expand All @@ -24,7 +27,7 @@ func NewRedisCloser(opts *RedisCloserOptions) (RDCloser, error) {
if !strings.Contains(opts.URL, ",") {
options, err := redis.ParseURL(opts.URL)
if err != nil {
return nil, fmt.Errorf("failed to parse the redis connection url %s: %w", opts.URL, err)
return nil, fmt.Errorf("failed to parse the redis connection url: %w", err)
}

if opts.Password != "" {
Expand All @@ -41,7 +44,7 @@ func NewRedisCloser(opts *RedisCloserOptions) (RDCloser, error) {
Password: opts.Password,
})
if !isFunctioningClient(rdb) {
return rdb, fmt.Errorf("failed to create a functioning redis client. Ensure that you have provided multiple cluster URLs for a cluster client")
return rdb, fmt.Errorf("failed to create a functioning redis client")
}
}

Expand Down

0 comments on commit fbe58fc

Please sign in to comment.