How can I set up Redis caching using RedisSessionStateProvider?

I am creating a sample MVC application using RedisSessionStateProvider as a custom session state. I am setting a variable to session state and it works fine. But I don't know how to synchronize the expiration of items in session and Redis. Can anyone please help?

These are the parameters from web.config

        <!--
      <add name="MySessionStateStore" 
        host = "127.0.0.1" [String]
        port = "" [number]
        accessKey = "" [String]
        ssl = "false" [true|false]
        throwOnError = "true" [true|false]
        retryTimeoutInMilliseconds = "5000" [number]
        databaseId = "0" [number]
        applicationName = "MvcTestApp" [String]
        connectionTimeoutInMilliseconds = "5000" [number]
        operationTimeoutInMilliseconds = "1000" [number]
        connectionString = "<Valid StackExchange.Redis connection string>" [String]
        loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
        loggingMethodName = "<Logging method should be defined in loggingClass. It should be public, static, does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
      />
    -->

      

I am using lateset versions: RedisSessionStateProvider version 1.6.4 Redis version 2.8.21

+3


source to share


2 answers


All session state providers do not have an expiration attribute. There is HttpSessionState.Timeout

Gets and sets the amount of time, in minutes, allowed between requests before the session state provider ends a session.

The Timeout property cannot be set to a value greater than 525,600 minutes (1 year). The default is 20 minutes.



So asp.net manages this logic for us, we don't need to worry about it.

In the redis client, you can use two commands keys *

to see all the keys ttl <key>

, to see when it will expire.

+1


source


Session items set in Redis expire, when the session expires, you don't need to do anything. It will be handled by RedisSessionStateProvider



+2


source







All Articles