在这里说的是在C#中的使用,在C#中使用是需要引入驱动的,
可以在网上找,这里推荐一个链接http://sourceforge.net/projects/memcacheddotnet/
将Memcached.ClientLibrary;引入。另外的 commands.dll log4net.dll,ICSharpCode.SharpZipLib.dll
等,应该是被以来的,下面的代码显示,使用到的类只在Memcacahed.ClientLibrary程序集中。其中log4net是
memcache记录日志所用。
简单的代码如下:
using Memcached.ClientLibrary;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace memcache{ class Program { static void Main(string[] args) { string[] server = { "10.21.160.31:11211"}; SockIOPool pool = SockIOPool.GetInstance();//在Memcached.ClientLibrary程序集里。 pool.SetServers(server); pool.InitConnections = 3; pool.MinConnections = 3; pool.MaxBusy = 5; pool.SocketConnectTimeout = 1000; pool.SocketTimeout = 3000; pool.MaintenanceSleep = 30; pool.Failover = true; pool.Nagle = false; pool.Initialize(); //获得客户端实例 MemcachedClient client = new MemcachedClient();//在Memcached.ClientLibrary程序集里 client.EnableCompression = false; client.Add("keyd1", "value12dfsdf", DateTime.Now.AddHours(1), 0); Console.WriteLine(client.Get("keyd1").ToString()); Console.ReadKey(); } }}