Stackexchange.Redis (C#)
是否支持连接到最新版本的哨兵集群以实现高可用性?我发现redis
的这一重要功能没有得到适当的记录,或者根本没有任何示例,这有点奇怪。不胜感激。
答案 0 :(得分:0)
通用Redis客户端https://stackexchange.github.io/StackExchange.Redis/
您可能正在寻找来源和文档
答案 1 :(得分:0)
您可以通过检查StackExchange.Redis的测试来查看如何连接到哨兵。具体来说,这一个https://github.com/StackExchange/StackExchange.Redis/blob/master/tests/StackExchange.Redis.Tests/Sentinel.cs
基本上,您需要查看的代码在这里:
public Sentinel(ITestOutputHelper output) : base(output)
{
ConnectionLog = new StringWriter();
Skip.IfNoConfig(nameof(TestConfig.Config.SentinelServer), TestConfig.Current.SentinelServer);
Skip.IfNoConfig(nameof(TestConfig.Config.SentinelSeviceName), TestConfig.Current.SentinelSeviceName);
var options = new ConfigurationOptions()
{
CommandMap = CommandMap.Sentinel,
EndPoints = { { TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPort } },
AllowAdmin = true,
TieBreaker = "",
ServiceName = TestConfig.Current.SentinelSeviceName,
SyncTimeout = 5000
};
Conn = ConnectionMultiplexer.Connect(options, ConnectionLog);
Thread.Sleep(3000);
Assert.True(Conn.IsConnected);
Server = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPort);
}
然后在这里:
[Fact]
public void SentinelGetMasterAddressByNameTest()
{
var endpoint = Server.SentinelGetMasterAddressByName(ServiceName);
Assert.NotNull(endpoint);
var ipEndPoint = endpoint as IPEndPoint;
Assert.NotNull(ipEndPoint);
Log("{0}:{1}", ipEndPoint.Address, ipEndPoint.Port);
}