Is it possible to have different passwords for each endpoint in StackExchange.Redis

49 Views Asked by At

I am trying to setup endpoints for master and slave. As per the Basics documentation https://stackexchange.github.io/StackExchange.Redis/Configuration.html you can connect to multiple Redis servers, and StackExchange.Redis will automatically determine the master/slave setup.

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("server1:6379,server2:6379");

Is it possible to have different passwords for master and slave setup?

Here is my code for Master setup, i can add more endpoints to setup slave but not sure if Redis allows different passwords for Master and Slave.

  var configurationOptions = new ConfigurationOptions
  {
   EndPoints = { { cachedserver.Host, cachedserver.Port }, },
   Password = cachedserver.Password,
   SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
  };
1

There are 1 best solutions below

3
sa-es-ir On

The redis connection string format is like this:

arbitrary_usrname:password@ipaddress:6379

So by having multiple connection strings separated by comma (,) you can achieve it:

ConnectionStrings:

arbitrary_usrname1:password@ipaddress1:6379,arbitrary_usrname2:password@ipaddress2:6379

Code:

var configurationOptions = ConfigurationOptions.Parse("connectionStrings");

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions);//also you can pass connectionStrings directly