I have a master-slave configuration with two slaves and three sentinels. If I try the commands with command-line everything is ok. But I have some problems configuring it for C#. I am using StackExchange.Redis library. But I don't understand what I should do in order to get/set the keys from the master. Should I manually find the master and then get or set the keys or does it do it autonomously? What is the best way to do it? Each time i want to get/set a key should I check who is the master? For now I did only this and I left my the other code as it was with only one master.
private static string ServiceName = "mymaster";
private static string IP { get { return "127.0.0.1"; } }
private static int Port = 26379;
public static readonly ConnectionMultiplexer Connection = GetConn();
public static readonly IServer Server = Connection.GetServer(IP, Port);
public static ConnectionMultiplexer GetConn()
{
try
{
// create a connection
var options = new ConfigurationOptions()
{
CommandMap = CommandMap.Sentinel,
EndPoints = { { IP, Port } },
AllowAdmin = true,
TieBreaker = "",
ServiceName = ServiceName,
SyncTimeout = 5000,
AbortOnConnectFail = true,
Ssl = false
};
var connection = ConnectionMultiplexer.Connect(options, Console.Out);
return connection;
}
catch (Exception ex)
{
ASLog.LogError(ex, 1);
return null;
}
}
where I have one of the three sentinels at port 26379. Sorry but I am a bit confused how to use this with C#.