Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 786
Chris Bohatka Avatar asked Oct 30 '22 20:10

Chris Bohatka


1 Answers

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.

like image 148
wami Avatar answered Nov 13 '22 15:11

wami