首先导入StackExchange.Redis
再创建一个redishelper类,百度一堆
最后创建测试类,增删查
public ActionResult redis(string s)
{
try
{
string redisconf = "127.0.0.1:6379,password=,DefaultDatabase=0";
RedisHelper.SetCon(redisconf);
List<object> li = new List<object>();
object o;
li.Add("{123,12,12,12,1,2,12,21}");
//存
RedisHelper.Set("118", li, 10000);//键,值,过期时间
//取
o = RedisHelper.Get("118");
//移除
// s = RedisHelper.Remove("118").ToString();
return Json(o, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(ex, JsonRequestBehavior.AllowGet);
}
}