Sitecore Experience Platform

Walkthrough: Configuring a shared session state database using the Redis provider

Abstract

Learn how to use Redis as your shared session state store.

In a shared session state, all data that can be shared across multiple sessions, for example, the data related to contacts and devices, is collected and saved to the session state database.

A contact can make multiple parallel visits to a website, in which case each visit has its own private session state. However, some data can be shared between visits, such as device and contact related information.

Information that is shared between parallel visits by the same contact is stored in the shared session state store. This data is still private to the contact but it is accessible from all current sessions made by the same contact.

This walkthrough describes how to use Redis as your out of process shared session state store, using the Sitecore ASP.NET session state provider for Redis.

Note

Sitecore version 8.2 Update 1 and newer supports Redis for both on-premise and Azure installations. The Sitecore 8.2 initial release only supports Redis for Azure.

Note

Sitecore does not support Redis Cluster.

The Sitecore ASP.NET session state store provider for Redis enables you to use Redis as your session state store. The provider supports the SessionEnd event, which the xDB needs to track website visits.

Important

Do not make changes directly to the configuration files. Instead, you must create a patch file that performs the required changes during runtime.

To deploy a Redis session database:

  1. Choose between Azure Redis or Redis on premise. You can provision Azure Redis by using the instructions on the Microsoft Azure website or with Azure PowerShell.

  2. Go to <sitename>\Website\App_Config, open the ConnectionStrings.config file, and add the following connection string:

    <add name="sharedSession" connectionString="_host_:_port_number _" />
    
  3. Configure the connection string so that it points to your session database.

  4. Save your changes.

To configure Sitecore to use the shared session state provider for Redis, you must:

  1. Go to your website root folder, navigate to the Website\App_Config\Include folder.

  2. Open the Sitecore.Analytics.Tracking.Config file.

  3. Locate the line where you can define the default shared session state provider using the following path: sitecore/tracking/sharedSessionState.

  4. Update the sharedSessionState section to use Redis as the defaultProvider instead of InProc, as shown in the following example. Also, change the name attribute value to redis.

    <sharedSessionState defaultProvider="redis">      
          <providers>
            <clear />
            <add name="redis" type=" 
    Sitecore.SessionProvider.Redis.RedisSessionStateProvider, 
    Sitecore.SessionProvider.Redis " connectionString="sharedSession" pollingInterval="2" 
    applicationName="shared" />
          </providers>
        </sharedSessionState>

Important

Do not make changes directly to the configuration files. Instead, you must create a patch file that performs the required changes during runtime.

The Sitecore Experience platform supports a dedicated Redis server. This means that if you have an environment using a cluster of CD servers, you can configure some of the servers to only serve content but not to process the session state data by using the pollingEnabled setting.

With the pollingEnabled setting you can enable/disable expired session processing. For example, you can enable it on the CD servers that are dedicated to expiring sessions and disabled it on the live CD servers, (that serve content to visitors).

To configure the pollingEnabled setting for a shared session state, disable shared sessions processing:

  • In the Sitecore.Analytics.Tracking.config file, set the pollingEnabled value to false for your dedicated CD servers and leave it set to true for your live servers.

      <sharedSessionState defaultProvider="redis">
                    <providers>
                          …
                        <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis"
    connectionString="redis.sessions"   pollingEnabled="false" pollingInterval="2" applicationName="shared"/>
                    </providers>
    	             …
                </sharedSessionState>

Use the Redis provider settings reference to configure your session state. If you have configured everything correctly, session records will appear in your Redis session database after the first web request.

If it is not possible to create a dedicated Redis server, you can instead configure the pollingMaxExpiredSessionsPerSecond setting to reduce large spikes by inserting a delay between each expired session. Doing this ensures that during a spike, delivery is assigned the majority of resources before the expiration is processed. To configure the pollingMaxExpiredSessionsPerSecond setting for a shared session:

  1. Ensure there is enough waiting time for the CPU to allocate the majority of its time to web requests, in the web.config file, set a high value, such as 100.

  2. Configure the pollingMaxExpiredSessionsPerSecond setting for a shared session, add the setting to the Sitecore.Analytics.Tracking.config file and update its value to a higher number. Refer to the following example:

    <sharedSessionState defaultProvider="redis">
        <providers>
                          …
            <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis" connectionString="redis.sessions" pollingEnabled="false" pollingInterval="2" applicationName="shared" pollingMaxExpiredSessionsPerSecond="100"/>
        </providers>
    	…