.net memcache

2018-06-18 02:53:34来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

非常感谢csdn及冷月宫主让我很快学会了.net操作 memcache 文章转自:http://download.csdn.net/detail/e_wsq/4358982

C#存取Memcache的示例 1 将Commons.dll,ICSharpCode.SharpZipLib.dll,log4net.dll,Memcached.ClientLibrary.dll 等放到bin目录 2 引用Memcached.ClientLibrary.dll

 1   string[] serverlist = { "127.0.0.1:11211", "90.0.12.120:11211" };
 2 
 3             //初始化池
 4             SockIOPool pool = SockIOPool.GetInstance();
 5             pool.SetServers(serverlist);
 6 
 7             pool.InitConnections = 3;
 8             pool.MinConnections = 3;
 9             pool.MaxConnections = 5;
10 
11             pool.SocketConnectTimeout = 1000;
12             pool.SocketTimeout = 3000;
13 
14             pool.MaintenanceSleep = 30;
15             pool.Failover = true;
16 
17             pool.Nagle = false;
18             pool.Initialize();
19 
20             // 获得客户端实例
21             MemcachedClient mc = new MemcachedClient();
22             mc.EnableCompression = false;
23 
24             Console.WriteLine("------------测   试-----------");
25             mc.Set("test1", "this is test");  //存储数据到缓存服务器,这里将字符串"my value"缓存,key 是"test"
26 
27             if (mc.KeyExists("test"))   //测试缓存存在key为test的项目
28             {
29                 Console.WriteLine("KEY为test的值正确写入");
30                 Console.WriteLine("test的值是:"+mc.Get("test").ToString());  //在缓存中获取key为test的项目
31             }
32             else
33             {
34                 Console.WriteLine("test not Exists");
35             }
36 
37            // Console.ReadLine();
38             var tt = mc.Get("test");
39             //mc.Delete("test");  //移除缓存中key为test的项目
40            
41             if (mc.KeyExists("test"))
42             {
43                 Console.WriteLine("test is Exists");
44                 Console.WriteLine(mc.Get("test").ToString());
45             }
46             else
47             {
48                 Console.WriteLine("值已删除");
49             }
50             //Console.ReadLine();
51 
52             SockIOPool.GetInstance().Shutdown();  //关闭池, 关闭sockets
View Code

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:windows 服务

下一篇:数据库访问辅助类SqlHelper