Skip to content
A Redis based SessionStateStoreProvider written in C# using ServiceStack.Redis.
C# CSS Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests #26 - Use HttpContext.Session.Timeout instead of the value from the w… Mar 27, 2015
tools Initial commit. Jun 8, 2012
.gitattributes Initial commit. Jun 8, 2012
.gitignore Use a distributed lock instead of watching the key. Feb 18, 2014
LICENSE Add license file for clarity. Mar 11, 2014 Bump version to 1.4.0 and update readme. Mar 27, 2015


This is a Redis based SessionStateStoreProvider written in C# using ServiceStack.Redis.


  1. You can either install using NuGet: PM> Install-Package Harbour.RedisSessionStateStore
  2. Or build and install from source: msbuild .\build\build.proj


Configure your web.config to use the session state provider:

  <sessionState mode="Custom" customProvider="RedisSessionStateProvider">
      <clear />
      <add name="RedisSessionStateProvider" 
           host="localhost:6379" clientType="pooled" />

This configuration will use a PooledRedisClientManager and use the default host and port (localhost:6379). Alternatively you can use the host attribute to set a custom host/port. If you wish to change the client manager type to BasicRedisClientManager, you can set the clientType="basic".

If you require that a custom IClientsManager be configured (for example if you're using an IoC container or you wish to only have one IClientsManager for your whole application), you can do the following when the application starts:

private IRedisClientsManager clientManager;

protected void Application_Start()
    // Or use your IoC container to wire this up.
    this.clientManager = new PooledRedisClientManager("localhost:6379");

    // Configure options on the provider.
    RedisSessionStateStoreProvider.SetOptions(new RedisSessionStateStoreOptions()
        KeySeparator = ":",
        OnDistributedLockNotAcquired = sessionId =>
            Console.WriteLine("Session \"{0}\" could not establish distributed lock. " +
                              "This most likely means you have to increase the " +
                              "DistributedLockAcquireSeconds/DistributedLockTimeoutSeconds.", sessionId);

protected void Application_End()



  • Use the HttpContext.Session.Timeout instead of the timeout from the web.config so that the request can customize the session's timeout.


  • Use a distributed lock rather than the WATCH/UNWATCH pattern because it was causing issues.
  • Add the ability to configure the provider with static SetOptions(options).


  • Always ensure UNWATCH is called.
  • Retry a transaction once if it fails.


  • Add WATCH/UNWATCH pattern for transactions.


  • Initial release.
You can’t perform that action at this time.