ASP.net MVC +redis联合开发框架搭建
1:下载redis for windows or linux安装并开启服务,并在vs的工具菜单下安装nuget
2:建立asp.net mvc4项目(internet app)
3:通过nuget 图形界面或者命令行安装redis(其实可以拷贝stackservice.redis.dll等几个相关文件)(要么,命令行安装,要么选择.net3.5再改回来,要么图形界面不要选那个黑色的redis c#,要么拷贝dll)才能成功安装.
4:添加引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ServiceStack.Redis;
using System.Collections;
using ServiceStack.Common;
4:替换HomeController类中的Index方法:
public ActionResult Index() {
RedisClientManagerConfig RedisConfig = new RedisClientManagerConfig(); RedisConfig.AutoStart = true; RedisConfig.MaxReadPoolSize = 60; RedisConfig.MaxWritePoolSize = 60; PooledRedisClientManager prcm = new PooledRedisClientManager(new List<string>() { "127.0.0.1" }, new List<string>() { "127.0.0.1" }, RedisConfig);
using (IRedisClient RClient = prcm.GetClient()) { IRedisHash obj=(IRedisHash)(new Hashtable()); obj["ef"] = "gfh"; RClient.Add("p1", "Hello world"); RClient.Set("p1", "hello,234"); RClient.Add("myhash", obj); } using (IRedisClient RClient = prcm.GetClient()) { Response.Write(RClient.Get<string>("p1")); }
return Content("");
}
5:运行
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。