1

I have a simple redis cluster on my local machine that consists of:

  • master on port 3679
  • slave on port 6380
  • sentinel on port 26379

I am using ServiceStack.Redis to connect with no problems so far. Today I added a password to each of them using the requirepass 42 setting. I can connect to all of them using Redis Desktop Manager fine and everything works as expected.

Using the following code, I get an error when I attempt to connect. Removing the password works as expected.

var config = RedisConfiguration.Instance;

Func<string, string> hostFilter = host => string.IsNullOrEmpty(config.SecurityKey)
                                    ? $"{host}?db={config.Database}"
                                    : $"{config.SecurityKey}@{host}?db={config.Database}";


var sentinelHosts = config.SentinelHosts.Select(hostFilter);
var sentinel = new RedisSentinel(sentinelHosts, config.ServiceName)
{
    HostFilter = hostFilter,
    RedisManagerFactory = (master, slaves) => new RedisManagerPool(master)
};

sentinel.OnFailover += manager => Logger?.Warn($"Redis fail over to {sentinel.GetMaster()}");

sentinel.Start()

This code throw a RedisException "No Redis Sentinels were available" with an inner exception of "unknown command 'AUTH'".

I am not clear if I am using the ServiceStack.Redis library improperly or my Redis cluster configuration is incorrect.

Can some one point me in the right direction?

NotMyself
  • 29,209
  • 17
  • 56
  • 74

1 Answers1

1

You can use HostFilter to specify the password:

sentinel.HostFilter = host => $"{config.SecurityKey}@{host}?db={config.Database}";

But when using a password, it needs to be configured everywhere, i.e. in both Master and Slave configurations using:

requirepass password
masterauth password

The Redis Sentinels also need to be configured to use the same password so it can control the redis instances it's monitoring, which can be configured in your sentinel.conf with:

sentinel auth-pass mymaster pasword

The windows-password folder in the redis-config project shows an example of a password-protected Redis Sentinel configuration.

mythz
  • 141,670
  • 29
  • 246
  • 390
  • This looks like it could be the root cause of my issue. I will give it a try and see if I can get it working. – NotMyself Feb 15 '17 at 22:24
  • Ok, you got me moving in the right direction. In the end I had to add `requirepass` and `masterauth` to the config for my master and slave and then turn `protected-mode` to no for my sentinel. That seemed to do the trick. [Here are my conf files](https://gist.github.com/NotMyself/49bafe59daf68efd18992ce852ac03cb) does this make sense? – NotMyself Feb 16 '17 at 00:51
  • @NotMyself looks ok from here. – mythz Feb 16 '17 at 02:34