Giter Site home page Giter Site logo

huangyuan / harbour.redissessionstatestore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thecloudlesssky/harbour.redissessionstatestore

0.0 2.0 0.0 9.91 MB

A Redis based SessionStateStoreProvider written in C# using ServiceStack.Redis.

License: MIT License

C# 97.96% CSS 1.63% ASP 0.23% Batchfile 0.19%

harbour.redissessionstatestore's Introduction

Harbour.RedisSessionStateStore

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

Installation

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

Usage

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

<system.web>
  <sessionState mode="Custom" customProvider="RedisSessionStateProvider">
    <providers>
      <clear />
      <add name="RedisSessionStateProvider" 
           type="Harbour.RedisSessionStateStore.RedisSessionStateStoreProvider" 
           host="localhost:6379" clientType="pooled" />
    </providers>
  </sessionState>
</system.web>

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");
    RedisSessionStateStoreProvider.SetClientManager(this.clientManager);

    // 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()
{
    this.clientManager.Dispose();
}

Changelog

v1.4.0

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

v1.3.0

  • 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).

v1.2.0

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

v1.1.0

  • Add WATCH/UNWATCH pattern for transactions.

v1.0.0

  • Initial release.

harbour.redissessionstatestore's People

Contributors

thecloudlesssky avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.