gpt4 book ai didi

c# - 无法使用 ASP.NET Redis SessionState Provider 连接到本地 Redis Sentinel 故障转移系统

转载 作者:可可西里 更新时间:2023-11-01 11:48:35 27 4
gpt4 key购买 nike

我有一个使用 Sentinels 设置的本地 Redis 环境以进行故障转移。我试图在我的 MVC 应用程序中使用 Redis 作为我的 SessionStateProvider。我已经安装了 Microsoft.Web.RedisSessionStateProvider NuGet 包,并且我有我的提供商的 web.config 条目。阅读微软的announcement blog post对于此提供程序,似乎只是通过 connectionString 属性添加了对多个主机的支持。

通过对公告博客帖子的评论提出的问题:

@Siddarth

The StackExchange.Redis Redis client allows for multiple hosts to be listed using the ConnectionMultiplexer, as seen github.com/.../Basics.md. How could I go about setting multiple hosts to pass through to the Redis client? In a previous comment you mentioned opening up the optionsString that can be set, in which case we would be able to pass through multiple hosts.

响应:

@Dvorac

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

you can pass this "server1:6379,server2:6379" using "connectionString" settings in session state provider.

除了这篇博文和评论,我试图找到更多的文档,但我一直找不到任何实质性的东西。在寻找更多信息的过程中,我相信我读到过提供者应该能够通过遍历所有提供的主机来确定哪个是主服务器。

截至目前,我 99% 确定我需要使用 connectionString 来允许多个主机,尽管我只有 1% 确定此 RedisSessionStateProvider 具有 Sentinel 支持。我一直在努力制作一个合适的 connectionString,目前面临以下异常:

An exception of type 'StackExchange.Redis.RedisConnectionException' occurred in Microsoft.Web.RedisSessionStateProvider.dll but was not handled in user code

Additional information: No connection is available to service this operation: EVAL

我的 connectionString 遵循以下格式:

connectionString="1.2.3.4:5,1.2.3.4:5,1.2.3.4:5,1.2.3.4:5,1.2.3.4:5,1.2.3.4:5,ssl=true,密码=XXXXXX,abortConnect=false"

如果有人有任何信息可以引导我朝着正确的方向前进,我将不胜感激。

我已经设置了一个 telnet 并且我已经将消息发送到 Redis 服务器,所以我知道我可以访问并且可以从我的机器建立连接。我忍不住觉得我没有正确编写 connectionString 或 ASP.NET session 状态提供程序无法处理此配置,我应该考虑构建一些自定义的东西。

最佳答案

StackExchange.Redis 客户端支持多台服务器,但它是关于主从而不是多主支持(如集群)。 ASP.NET Redis Session 提供程序不支持主/从,实际上去从属是没有用的,因为你只能从它读取(你只能将它用于只读 session )。
如果您想为本地 Redis 服务器设置高可用性,则必须使用内部 DNS 服务器并为您的 Redis session 实例创建记录。您应该在 web.config 中使用该 DNS 记录而不是 IP,因为当发生故障转移时,您将使用新的主 IP 更新该 DNS 条目。

关于c# - 无法使用 ASP.NET Redis SessionState Provider 连接到本地 Redis Sentinel 故障转移系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31611528/

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