gpt4 book ai didi

c# - 如何使用 StackExchange.Redis 连接到哨兵集群?

转载 作者:可可西里 更新时间:2023-11-01 11:24:04 28 4
gpt4 key购买 nike

Stackexchange.Redis (C#) 是否支持连接到哨兵集群以获得最新版本的高可用性?我发现 redis 如此重要的特性没有正确记录或几乎没有示例,这有点奇怪。非常感谢任何帮助。

最佳答案

您可以通过检查 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);
}

关于c# - 如何使用 StackExchange.Redis 连接到哨兵集群?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53498605/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com