Asp.Net分布式缓存Redis之Session框架

     尽管Session在某些方面,并不尽如人意,关于它的种种利弊,也都是各种云(人云亦云、众说纷纭)。可在面对一些项目的时候,我不得不采用它来存储一些信息,来实现某些功能。在某项项目里,我采用Redis缓存服务,实现自定义Session。

   在这里,我推荐两款基于Redis的Session框架,一种是Harbour.RedisSessionStateStore,但是它好像有段时间未更新了。我们可以在这里https://www.nuget.org/packages/Harbour.RedisSessionStateStore/

通过nuget工具来安装到工程里。

gitHub的下载地址:https://github.com/TheCloudlessSky/Harbour.RedisSessionStateStore

  另一种,是微软提供的

RedisSessionStateProvider 组件。安装方法如下图:


RedisSessionStateProvider的安装方式,非常简单。安装完成后,只需要在你的Web.config中,添加下配置


<sessionState mode="Custom"  cookieName="TiKuSession" customProvider="MySessionStateStore">
      <providers>
        <!-- Either use 'connectionString' and provide all parameters as string OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. -->
        <!-- 'throwOnError','retryTimeoutInMilliseconds','databaseId' and 'applicationName' can be used with both options. -->
        <!--
          <add name="MySessionStateStore" 
            host = "127.0.0.1"
            port = "6379"
            accessKey = "" [String]
            ssl = "false" [true|false]
            throwOnError = "true" [true|false]
            retryTimeoutInMilliseconds = "5000" [number]
            databaseId = "0" [number]
            applicationName = "" [String]
            connectionTimeoutInMilliseconds = "5000" [number]
            operationTimeoutInMilliseconds = "1000" [number]
            connectionString = "<Valid StackExchange.Redis connection string>" [String]
            loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
            loggingMethodName = "<Logging method should be defined in loggingClass. It should be public, static, does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
          />
        -->
        <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="127.0.0.1" port="6379" accessKey="" ssl="false" />
      </providers>
    </sessionState>
接下来,让我们一起来感受下。


预览下:

看下我们的Redis服务里存储了什么?

好了,先写到这儿吧。若有想法,欢迎探讨。

转载于:https://my.oschina.net/lichaoqiang/blog/639916

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值