Giter Site home page Giter Site logo

lucifer11111 / redisaspnetproviders Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alex-simonov/redisaspnetproviders

0.0 1.0 0.0 8.36 MB

Redis backed ASP.NET providers written in C# using StackExchange.Redis.

License: MIT License

C# 100.00%

redisaspnetproviders's Introduction

RedisAspNetProviders Build status

Redis backed ASP.NET providers written in C# using StackExchange.Redis. Includes the following providers:

  • OutputCacheProvider;
  • SessionStateStoreProvider.

To use RedisAspNetProviders in your project it must meet the following requirements:

  1. .NET 4.0 or later.
  2. Redis 2.6.0 or later.

To build RedisAspNetProviders and run tests you will need Visual Studio 2013.

Installation

  1. RedisAspNetProviders can be installed via the nuget UI (as RedisAspNetProviders) or via the nuget package manager console:

     PM> Install-Package RedisAspNetProviders
    
  2. Alternatively, you can grab sources from here and build.

Configure connection to Redis:

Add a connection string for Redis and specify the connectionStringName for provider:

<connectionStrings>
  <add name="RedisConnectionString" connectionString="192.168.0.120,connectTimeout=5000" />
</connectionStrings>
<system.web>
  ...
  <sessionState mode="Custom" customProvider="RedisSessionStateStoreProvider"> 
    <providers>
      <add name="RedisSessionStateStoreProvider"
           type="RedisAspNetProviders.SessionStateStoreProvider, RedisAspNetProviders"
           connectionStringName="RedisConnectionString" />
    </providers>
  </sessionState>
  ...
  <caching>
    <outputCache defaultProvider="RedisOutputCacheProvider">
      <providers>
        <add name="RedisOutputCacheProvider"
             type="RedisAspNetProviders.OutputCacheProvider, RedisAspNetProviders"
             connectionStringName="RedisConnectionString" />
      </providers>
    </outputCache>
  </caching>
  ...
</system.web>

... or specify the connectionString directly:

<system.web>
  ...
  <sessionState mode="Custom" customProvider="RedisSessionStateStoreProvider"> 
    <providers>
      <add name="RedisSessionStateStoreProvider"
           type="RedisAspNetProviders.SessionStateStoreProvider, RedisAspNetProviders"
           connectionString="192.168.0.120,connectTimeout=10000" />
    </providers>
  </sessionState>
  ...
  <caching>
    <outputCache defaultProvider="RedisOutputCacheProvider">
      <providers>
        <add name="RedisOutputCacheProvider"
             type="RedisAspNetProviders.OutputCacheProvider, RedisAspNetProviders"
             connectionString="192.168.0.121,connectTimeout=10000" />
      </providers>
    </outputCache>
  </caching>
  ...
</system.web>

For additional information about configuring connection to Redis you can read `StackExchange.Redis``s documentation.

Additional configuration parameters

All providers support several optional parameters:

  • dbNumber allows you to specify a number of the database which will store sessions; by default dbNumber=0;
  • keyPrefix allows you to specify a prefix for the RedisKey which will be used to store session state in Redis; by default keyPrefix="".
<system.web>
  ...
  <sessionState mode="Custom" customProvider="RedisSessionStateStoreProvider"> 
    <providers>
      <add name="RedisSessionStateStoreProvider"
           type="RedisAspNetProviders.SessionStateStoreProvider, RedisAspNetProviders"
           connectionString="192.168.0.120:6379"
           dbNumber="1"
           keyPrefix="MyWebApplication/SessionState/" />
    </providers>
  </sessionState>
  ...
  <caching>
    <outputCache defaultProvider="RedisOutputCacheProvider">
      <providers>
        <add name="RedisOutputCacheProvider"
             type="RedisAspNetProviders.OutputCacheProvider, RedisAspNetProviders"
             connectionString="192.168.0.121:6379,connectTimeout=10000"
             dbNumber="1"
             keyPrefix="MyWebApplication/OutputCache/" />
      </providers>
    </outputCache>
  </caching>
  ...
</system.web>

Note: If you want to implement your own rules for choosing a Redis database or formatting a RedisKey you can override SessionStateStoreProvider.GetSessionStateStorageDetails(httpContext, sessionId) and OutputCacheProvider.GetCacheEntryStorageDetails(cacheEntryKey) methods. By default these methods return configured via dbNumber Redis database proxy and RedisKey which is generated as keyPrefix + sessionId for SessionStateStoreProvider and keyPrefix + cacheEntryKey for OutputCacheProvider.

Custom serialization, compression, etc.

All providers have protected virtual methods Serialize***() and Deserialize***(). Feel free to inherit from necessary provider and implement your own serialization mechanism.

redisaspnetproviders's People

Contributors

alex-simonov avatar

Watchers

James Cloos 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.