web开发 那些年基于Redis的Provider库
因为session基于本地cache,以前我们自己写分布式缓存,或者数据库存储,或者cookie加密存储,来保存用户状态信息,但较少的直接通过创建一个继承 SessionStateStoreProviderBase 类,来实现自定义会话状态存储提供程序。但有ASP.NET官方的福利,我们就不能放过。
Microsoft.Web.RedisOutputCacheProvider,没错就是它,此库底层用的正是StackExchange来访问redis
当然,不止MS写了,这个也是可以滴:https://github.com/alex-simonov/RedisAspNetProviders
redis戳此入门:http://www.cnblogs.com/NotAnEmpty/p/5441127.html
研究内部实现可参考其下
参考:https://github.com/Azure/aspnet-redis-providers
https://msdn.microsoft.com/zh-cn/library/ms178587(VS.80).aspx
天色尚未晚 媳妇还未还,还有时间 干点正事吧...
Install-Package Microsoft.Web.RedisSessionStateProvider
webconfig出现一小坨,如果用的是Azure的Redis,那你需要填一下host和accesskey,否则也没啥好改的
<sessionState mode="Custom" customProvider="MySessionStateStore">
<providers>
<!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki -->
<!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' 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" [String]
port = "" [number]
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]
settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
settingsMethodName = "<Settings method should be defined in settingsClass. It should be public, static, does not take any parameters and should have a return type of 'String', which is basically 'connectionString' value.>" [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" connectionString="127.0.0.1:6379,allowadmin=true" accessKey="" ssl="true" />
</providers>
</sessionState>
接着我们看看它能干啥?
//Action Index中,就两句,view直接输出Model
Session["UserAgent"] = Request.UserAgent;
ViewData.Model = "访问状态已分布式存储session"; //然后我们访问另一个About,然后直接输出Session:@Model
//不出意料的出现了:Session:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36
//当然你们是看不到,我反正看到了,但看不到也不是重点
ViewData.Model = Session["UserAgent"];
重点来了,有图有真相,分布式Session完毕

这么屌,是否能搞OutputCacheProvider?搞搞不要钱
Install-Package Microsoft.Web.RedisOutputCacheProvider
依旧免费给的一大坨
<caching>
<outputCache defaultProvider="MyRedisOutputCache">
<providers>
<!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki -->
<!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. -->
<!-- 'databaseId' and 'applicationName' can be used with both options. -->
<!--
<add name="MyRedisOutputCache"
host = "127.0.0.1" [String]
port = "" [number]
accessKey = "" [String]
ssl = "false" [true|false]
databaseId = "0" [number]
applicationName = "" [String]
connectionTimeoutInMilliseconds = "5000" [number]
operationTimeoutInMilliseconds = "1000" [number]
connectionString = "<Valid StackExchange.Redis connection string>" [String]
settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
settingsMethodName = "<Settings method should be defined in settingsClass. It should be public, static, does not take any parameters and should have a return type of 'String', which is basically 'connectionString' value.>" [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="MyRedisOutputCache" type="Microsoft.Web.Redis.RedisOutputCacheProvider" connectionString="127.0.0.1:6379,allowadmin=true" accessKey="" ssl="true" />
</providers>
</outputCache>
</caching>
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
[OutputCache(Duration = 60, VaryByParam = "*")]
public ActionResult RedisCacheIndex()
{
ViewData.Model = DateTime.Now.ToString();
return View();
}
当然访问此页面怎么刷新都是同一个时间,但我们要学会寻找重点
虽然真相就在眼前


欢迎转载,来爬我啊:http://www.cnblogs.com/NotAnEmpty/p/5441127.html
web开发 那些年基于Redis的Provider库的更多相关文章
- ASP.NET基于Redis的Provider库
因为session基于本地cache,以前我们自己写分布式缓存,或者数据库存储,或者cookie加密存储,来保存用户状态信息,但较少的直接通过创建一个继承 SessionStateStoreProvi ...
- 向 Web 开发人员推荐35款 JavaScript 图形图表库
图表是数据图形化的表示,通过形象的图表来展示数据,比如条形图,折线图,饼图等等.可视化图表可以帮助开发者更容易理解复杂的数据,提高生产的效率和 Web 应用和项目的可靠性. 在这篇文章中,我们收集了3 ...
- 超全的web开发工具和资源
首页 新闻 产品 地图 动态 城市 帮助 论坛 关于 登录 注册 · 不忘初心,继续前进,环境云V2接口正式上线 · 环境云测点地图全新改版 · 祝福各位环境云用户中秋快乐! 平台信息 培训互动 ...
- 干货100+ 最超全的web开发工具和资源大集合
干货100+ 最超全的web开发工具和资源大集合 作为Web开发者,这是好的时代,也是坏的时代.Web开发技术也在不断变化.虽然很令人兴奋,但是这也意味着Web开发人员需要要积极主动的学习新技术和 ...
- Python做web开发,推荐几个能立马上手的小项目
Python这门优美的语言是非常适合web开发的,基于Python的Django框架简单便捷且很强大. 那么作为新手该如何上手这门语言?一切不敲代码的学编程手段都是扯淡,今天就推荐一些适合新手练手的P ...
- Redis的Python实践,以及四中常用应用场景详解——学习董伟明老师的《Python Web开发实践》
首先,简单介绍:Redis是一个基于内存的键值对存储系统,常用作数据库.缓存和消息代理. 支持:字符串,字典,列表,集合,有序集合,位图(bitmaps),地理位置,HyperLogLog等多种数据结 ...
- Redis在WEB开发中的应用与实践
Redis在WEB开发中的应用与实践 一.Redis概述: Redis是一个功能强大.性能高效的开源数据结构服务器,Redis最典型的应用是NoSQL.但事实上Redis除了作为NoSQL数据库使用之 ...
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第3章节--SharePoint 2013 开发者工具 SharePoint中基于Web开发
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第3章节--SharePoint 2013 开发者工具 SharePoint中基于Web开发 之前提到过, ...
- 《Flask Web开发——基于Python的Web应用开发实践》一字一句上机实践(上)
目录 前言 第1章 安装 第2章 程序的基本结构 第3章 模板 第4章 Web表单 第5章 数据库 第6章 电子邮件 第7章 大型程序的结构 前言 学习Python也有一个半月时间了,学到现在感觉 ...
随机推荐
- 智课雅思词汇---二十三、名词性后缀mony
智课雅思词汇---二十三.名词性后缀mony 一.总结 一句话总结:Latin: action, result of an action or condition; a suffix that for ...
- yii2: 上传图片,生成目录
1.单个文件上传 首先建立一个模型models/UploadForm.php,内容如下 namespace app\models; use yii\base\Model; use yii\web\Up ...
- GitLab使用总结[转]
http://blog.csdn.net/huaishu/article/details/50475175 GitLab使用总结
- eclipse配置tomcat运行项目访问不加项目名
- Win7系统搭建WiFi热点详细攻略
(转自:http://blog.csdn.net/gisredevelopment/article/details/16113889) 一.如果你之前没有在笔记本上搭建过WiFi,那么恭喜你,你的笔记 ...
- LeetCode OJ:Add Binary(二进制相加)
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
- DMD数字微镜
Digital Micromirror Device DMD技术于1987年被发明,到1996年春走向市场.DMD是一个真正的微光机电系统(MOEMS),该器件是利用CMOS工艺和微机械加工(MEMS ...
- javascript: 代码优化
一.避免全局查找 在一个函数中会用到全局对象存储为局部变量来减少全局查找,因为访问局部变量的速度要比访问全局变量的速度更快些 function search() { //当我要使用当前页面地址和主机域 ...
- 初识Linux(五)--VI/VIM编辑器
我们操作文件,终究离不开编辑文件,对文件内容的编辑,Linux系统下,我们通常使用VI/VIM来编辑文件.VI是每个Linux都会自带的文本编辑器,VIM是VI的增强版,可能有些发行版本没有自带,可以 ...
- Struts2 用过滤器代替了 servlet ,???? 且不需要tomcat就可以直接做功能测试
Struts2 用过滤器代替了 servlet ,???? 且不需要tomcat就可以直接做功能测试