使用ASP.NET会话状态提供程序无法连接到Redis的服务器连接到、状态、服务器、程序

2023-09-04 12:54:47 作者:校长,借个火

我一直在尝试使用Redis的替换ASP.NET会话有一段时间了。多个小时的微软ASP.NET会话状态提供程序都石沉大海Redis的。

I have been attempting to replace ASP.NET Session with Redis for some time now. Multiple hours with the Microsoft ASP.NET Session State Provider for Redis have been fruitless.

我们有一个片premises哨兵配置Redis的。原本我以为这是行不通的,由于供应商不支持哨兵。我打开我的连接字符串使用高手,希望我会至少能够建立连接。依然什么也没有。

We have an on-premises Sentinel configuration for Redis. Originally I thought this was not working due to the Provider not supporting Sentinels. I switched my connection string to use the master, in hopes that I would at least be able to establish a connection. Still nothing.

我已经尝试了多种配置此提供程序,并不断地接受或无可用连接的请求或附加信息:这是不可能连接到Redis的服务器(S);要创建断开连接多路复用器,禁用AbortOnConnectFail 。UnableToResolvePhysicalConnection上PING。

I have tried multiple configurations for this provider and continually receive either "No connection available for the request" or "Additional information: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. UnableToResolvePhysicalConnection on PING."

下面是一些配置,我已经尝试的:

Here are some of the configurations I've attempted:

尝试#1:

<connectionStrings>
  <add name="RedisConnection" connectionString="1.2.3.4:5,abortConnect=false,ssl=true,password=XXXXXX,ConnectTimeout=10000"/>
</connectionStrings>

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="RedisConnection" />
  </providers>
</sessionState>

尝试#2:

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="1.2.3.4" port="5" accessKey="XXXXXXX" />
  </providers>
</sessionState>

尝试3:

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="1.2.3.4:5" accessKey="XXXXXXX" />
  </providers>
</sessionState>

我发现在此提供很少的文档,并排除故障一直是个难题。我碰到一个第三方提供商,并决定尝试一下,相比于微软提供者。

I have found very little documentation on this provider, and troubleshooting has been a challenge. I came across a third-party provider and decided to try it, compared to the Microsoft provider.

我是能够成功地与 Harbour.RedisSessionStateStore 的连接,使用以下配置:

I was able to successfully connect with Harbour.RedisSessionStateStore, using the following configuration:

<sessionState mode="Custom" customProvider="RedisSessionStateProvider">
  <providers>
    <clear />
    <add name="RedisSessionStateProvider" type="Harbour.RedisSessionStateStore.RedisSessionStateStoreProvider" host="PASSWORD@1.2.3.4:5" clientType="pooled" />
  </providers>
</sessionState>

通过这一点,什么是为微软提供者的连接字符串格式是否正确?这将是容易,我从第一方库获得内部支持,在这一点上,这将是一个道义上的胜利得到这个工作。

With this is mind, what is the correct format for a connection string for the Microsoft provider? It will be easier for me to receive internal support from a first party library, and at this point, it would be a moral victory to get this working.

此外,如果有人知道我怎么能配置该打的哨兵,并确定主实例连接,我将欢迎的博客文章或专题任何一种知识共享的。

Also, if anyone knows how I could configure this to hit the Sentinel and determine the master instance to connect to, I would welcome a blog post or any sort of knowledge share on the topic.

感谢您!

推荐答案

我可以给你的工作方案,这是我们在我们的生产,不定点的例子,而是直接将主:

I can give you an example of a working configuration, which we have in our production, no sentinel, but directly to the master:

<system.web>
  <sessionState mode="Custom" customProvider="Custom_RedisSessionStateStore">
    <providers>
    <add name="Custom_RedisSessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="your_host_name_goes_here" accessKey="" port="6379" ssl="false" operationTimeoutInMilliseconds="5000" />
    </providers>
  </sessionState>
</system.web>