简体   繁体   中英

Configure ASP.NET Redis Session State Provider for Sentinel Configuration

I have been trying to get the ASP.NET Redis Session State provider configured in my app for some time now. I was finally able to successfully connect directly to the master and set/get keys thanks to this post: Can't connect to Redis server using ASP.NET Session State Provider

Now, my next question...getting this to work with a Sentinel configuration.

I familiar with the SENTINEL get-master-addr-by-name master-dev-sessionstate command to determine the master. Does this provider have this built in? Based on the comments on the blog post linked above (which is also the ONLY documentation I can find on this) it appears that I should be able to use the connectionString attribute to pass multiple hosts. I'm not sure if these multiple hosts are intended to be Sentinels or not, though.

<connectionStrings>
  <add name="RedisConnection" connectionString="1.2.3.4:5,6.7.8.9:10,abortConnect=false,ssl=false,password=XXXXXX,operationTimeoutInMilliseconds=5000"/>
</connectionStrings>

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

When configuring my connection like this, I receive this error:

Additional information: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail.

I get this error even when I only have the master IP in my connection string. As you can see above, I have abortConnect="false" in my connection string, which is what it is instructing me to do. The same error occurs with or without this present in the connection string.

With this in mind, here are my questions...

  1. Does this provider support Sentinel configurations?
  2. If yes, what is the correct format for the connection string?
  3. Does anyone have any other good documentation resources for this? I haven't even been able to find anything on Microsoft's site outside of that blog post.

EDIT: I should note, this is a custom, local Redis install. We are not running through Azure.

EDIT: I recently tried to point my working configuration to a Sentinel and I receive "No connection is available to service this operation: EVAL." This leads me to believe that this provider does not have Sentinel support. Can anyone confirm this?

i am using this provider for a private redis install. As far as I understood the documentation this provider is using the package StackExchange.Redis.Strongname and the ConnectionMultiplexer for configuration. With this library it is possible to use the described configuration options . Furthermore this documentation states that the sentinel support (serviceName) is currently not implemented.

Nevertheless i wonder why you need to communicate with the sentinels, the ConnectionMultiplexer is able to resolve the master slave setup see Documentation. Moreover i tested this behavior by shutting down redis instances and took a look at the network traffic. Please take a look at the ConnectionMultiplexer documentation:

A more complicated scenario might involve a master/slave setup; for this usage, simply specify all the desired nodes that make up that logical redis tier (it will automatically identify the master): ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("server1:6379,server2:6379");

Additionally my configuration setup looks like this:

 <add   name="MySessionStateStore" 
    type="Microsoft.Web.Redis.RedisSessionStateProvider"
    connectionString="XXXXXX:6379,XXXXXX:6379,XXXXXX:6379"  
    applicationName="myFancyApp"ssl="false"/>

Regarding MS.RedisSessionState Provider i used the following tutorial beside the site .

This is what is normally added to web.config when you install the nuget package;

sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <!--
      <add name="MySessionStateStore" 
        host = "127.0.0.1" [String]
        port = "" [number]
        accessKey = "" [String]
        ssl = "false" [true|false]
        throwOnError = "true" [true|false]
        retryTimeoutInMilliseconds = "0" [number]
        databaseId = "0" [number]
        applicationName = "" [String]
        connectionTimeoutInMilliseconds = "5000" [number]
        operationTimeoutInMilliseconds = "5000" [number]
      />
    -->
    <add name="MySessionStateStore" 
         type="Microsoft.Web.Redis.RedisSessionStateProvider"
         host="127.0.0.1" 
         accessKey="" 
         ssl="false" />
  </providers>
</sessionState>

Here's one we use with an Azure cache server..

<sessionState mode="Custom" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider"
          type="Microsoft.Web.Redis.RedisSessionStateProvider"
          port="6380"
          host="xxxxxxxx.redis.cache.windows.net"
          accessKey="vCG........We0n="
          ssl="true"
          connectionTimeoutInMilliseconds = "5000"
          operationTimeoutInMilliseconds = "1000"
          retryTimeoutInMilliseconds="3000" />
  </providers>
</sessionState>

We set retry time out to 3 seconds with operation time out to 1 second, that allows 3 (1000/3000=3) attempts before it gives up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM