Walkthrough: Configuring a private session state database using the Redis provider
In private session state, all data related to a specific interaction, such as viewed pages, converted goals, triggered campaigns, or accumulated engagement points, is collected and saved to the session state database.
This walkthrough describes how to use Redis as your private session state store using the Sitecore ASP.NET Session State Store Provider for Redis. It describes how to deploy a private Redis session database, configure Sitecore, and adjust session state settings.
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.
Sitecore does not support Redis Cluster.
Deploy a private Redis session database
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.
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:
-
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.
-
Go to the
<sitename>\Website\App_Config\
folder, open theConnectionStrings.config
file, and add the following connection string:RequestResponse<add name="session" connectionString="_host_:_port_number _" />
-
Configure the connection string so that it points to your session database.
-
Save your changes.
Configure Sitecore
If you are using a Redis session provider, all content delivery servers must use the same provider pointing to the same database. To configure Sitecore to use the private session state store provider for Redis:
-
Go to your site root folder
<sitename>\website
, open theweb.config
file and locate thesesssionState
section:RequestResponse<sessionState mode="InProc" cookieless="false" timeout="20">
-
Update the
sessionState
section to use theredis
provider instead ofInProc
as shown in the following example. Also, change the value of thename
attribute toredis
:RequestResponse<sessionState mode="Custom" customProvider="redis" timeout="20"> <providers> <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis" connectionString="session" pollingInterval="2" applicationName="private"/> </providers> </sessionState>
Do not make changes directly to the configuration files. Instead, you must create a patch file that performs the required changes during runtime.
Configure a dedicated Redis Session Processing server
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 private session state, disable private sessions processing:
-
In the
web.config
file, set thepollingEnabled
value tofalse
for your dedicated CD servers and leave it set totrue
for your live servers.RequestResponse<sessionState mode="Custom" customProvider="redis" cookieless="false" timeout="1" sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager"> ... <providers> <add name="redis" type="Sitecore.SessionProvider.Redis.RedisSessionStateProvider, Sitecore.SessionProvider.Redis" applicationName="Application" connectionString="redis.sessions" pollingEnabled="false" pollingInterval="2" pollingMaxExpiredSessionsPerSecond="0" pollingMaxInstances="1" compression="true"/> </providers> </sessionState>
Adjust the Redis provider settings
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.
Alternative procedure to configure Redis session expiry throttling
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 private session:
-
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 as100
. -
Consult the Redis provider settings reference.