Redis Cluster - accept multiple addresses

with the redis cluster, the config accepts only one address, while the underlying go-redis library is expecting []string. Am I missing a way to provide multiple redis node IPs, or is this a feature that could be added to allow the use of a redis cluster?

The project doesn’t support redis cluster connection, however, you’re more than happy to contribute such feature. Looking at the go-redis pkg it needs an entirely new way to setup cluster client, so it will be a bit of work.

The project doesn’t support redis cluster connection,

The latest releases state support for redis cluster and redis sentinel.

The issue i see with the config is that it takes only one address as a string and the calls the redis library which takes a slice of strings.

You are right, I didn’t know it had recent redis cluster support.
I found this, but its true that the code just uses one URL from the redis scheme.

# Set this to true when the provided URL is pointing to a Redis Cluster
# instance.
cluster={{ .Redis.Cluster }}
if c.Redis.Cluster {
		redisClient = redis.NewClusterClient(&redis.ClusterOptions{
			Addrs:    []string{opt.Addr},
			PoolSize: opt.PoolSize,
			Password: opt.Password,
		})

So it only connects to one cluster node it seems.

You’ve got it exactly! Cluster is desired for HA, but it’s not very HA if only one node is provided if that node goes down. Right now cluster does work, but I’d like to be able to pass all the addresses via config.

Perhaps the redis section in the config could be:

Redis settings
#
# Please note that Redis 2.6.0+ is required.
[redis]
# Redis server or servers...
servers=[
    “10.10.10.10”, “10.10.10.11”
]

username=“foo”

password=“bar”

database=0

# Redis Cluster.
#
# Set this to true when the provided URL is pointing to a Redis Cluster 
# instance.
cluster=false

# The master name.
#
# Set the master name when the provided URL is pointing to a Redis Sentinel
# instance.
master_name=""

# Connection pool size.
#
# Default is 10 connections per every CPU.
pool_size=0

@brocaar how do you feel about this proposal? Shall I open a feature request issue in github for it?

1 Like

Yes, that would be great!