(二)在.net中如何使用Memcached

Step1:第一步当然是下载Memcached for c# API,

将这几个dll引用到项目中去

 

step2:上代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 using Memcached.ClientLibrary;
 7 
 8 namespace MvcDemo.Controllers
 9 {
10     public class MemCachedController : Controller
11     {
12         //
13         // GET: /MemCached/
14 
15         public ActionResult Index()
16         {
17 
18             string[] servers = { "172.16.200.67:41211" };
19             SockIOPool pool = SockIOPool.GetInstance("test");
20             pool.SetServers(servers);
21             pool.Initialize();
22             MemcachedClient memClient = new MemcachedClient();
23             memClient.PoolName = "test";
24             memClient.EnableCompression = false;
25             bool b= memClient.Set("k2", "lixiaofei",DateTime.Now.AddMinutes(2));
26             ViewBag.Name= memClient.Get("k2");
27             return Content(ViewBag.Name);
28         }
29 
30     }
31 }
View Code

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。