Regression in Sentinel support from version 2.1.30 to 2.1.58
Hi I am using the following code snippet to connect to redis using sentinel. full gist here
ConfigurationOptions configuration = new ConfigurationOptions();
configuration.ServiceName = "mymaster";
configuration.EndPoints.Add("127.0.0.1", 5000);
configuration.EndPoints.Add("127.0.0.1", 5001);
configuration.EndPoints.Add("127.0.0.1", 5003);
configuration.TieBreaker = "";
configuration.CommandMap = CommandMap.Sentinel;
ConnectionMultiplexer sentinel = ConnectionMultiplexer.Connect(configuration, Console.Out);
var masterConfig = new ConfigurationOptions() { ServiceName = "mymaster" };
ConnectionMultiplexer redis = sentinel.GetSentinelMasterConnection(masterConfig, Console.Out);
The above code works with version 2.1.30 but with 2.1.58 fails with the following error.
Unhandled exception. System.NotImplementedException: The ConnectionMultiplexer is not a Sentinel connection.
at StackExchange.Redis.ConnectionMultiplexer.GetSentinelMasterConnection(ConfigurationOptions config, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2362
at stackexchange.MainClass.Main(String[] args) in /Users/kyousaf/Dev/Development3/repo/stackexchange/Program.cs:line 23
@ejsmith do you think it's related to #1431 ?
ConnectionMultiplexer sentinel = ConnectionMultiplexer.Connect(configuration, Console.Out);
On the new version you need to use:
ConnectionMultiplexer sentinel = ConnectionMultiplexer.SentinelConnect(configuration, Console.Out);
With 2.1.58, I think that you can just use ConnectionMultiplexer.Connect to return the master connection. I have 3 sentinels running in 172.17.6.45~47 and port 26379 with service name as mymaster, then I can connect to master with the following code:
ConfigurationOptions configuration = new ConfigurationOptions();
configuration.ServiceName = "mymaster";
configuration.EndPoints.Add("172.17.6.45", 26379);
configuration.EndPoints.Add("172.17.6.46", 26379);
configuration.EndPoints.Add("172.17.6.47", 26379);
configuration.TieBreaker = "";
configuration.CommandMap = CommandMap.Default;
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configuration);
IDatabase db = redis.GetDatabase(0);
db.StringSet(....
Victor is correct above - "just connect" and it'll do what's needed. I missed it in the original but the problem generally is setting the command map - skip this step as it's not needed and will interfere with automatic detection in play. I hope that helps anyone finding this later - closing out to tidy up and happy to reopen if there are more questions.