.netmemcache

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: |||超大  

非常感谢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

1string[] serverlist = {"127.0.0.1:11211","90.0.12.120:11211"};23//初始化池4SockIOPool pool =SockIOPool.GetInstance();5pool.SetServers(serverlist);67pool.InitConnections =3;8pool.MinConnections =3;9pool.MaxConnections =5;1011pool.SocketConnectTimeout =1000;12pool.SocketTimeout =3000;1314pool.MaintenanceSleep =30;15pool.Failover =true;1617pool.Nagle =false;18pool.Initialize();1920//获得客户端实例21MemcachedClient mc =newMemcachedClient();22mc.EnableComPRession =false;2324Console.WriteLine("------------测 试-----------");25mc.Set("test1","this is test");//存储数据到缓存服务器,这里将字符串"my value"缓存,key 是"test"2627if(mc.KeyExists("test"))//测试缓存存在key为test的项目28{29Console.WriteLine("KEY为test的值正确写入");30Console.WriteLine("test的值是:"+mc.Get("test").ToString());//在缓存中获取key为test的项目31}32else33{34Console.WriteLine("test not Exists");35}3637//Console.ReadLine();38vartt = mc.Get("test");39//mc.Delete("test");//移除缓存中key为test的项目4041if(mc.KeyExists("test"))42{43Console.WriteLine("test is Exists");44Console.WriteLine(mc.Get("test").ToString());45}46else47{48Console.WriteLine("值已删除");49}50//Console.ReadLine();5152SockIOPool.GetInstance().Shutdown();//关闭池, 关闭sockets

View Code

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航