下载文件:https://sourceforge.net/projects/memcacheddotnet/
将Commons.dll,ICSharpCode.SharpZipLib.dll,log4net.dll,Memcached.ClientLibrary.dll 等放到bin目录
引用Memcached.ClientLibrary.dll
程序实例:
using Memcached.ClientLibrary; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Memcached随练 { class Program { static void Main(string[] args) { //分布Memcachedf服务IP 端口 string[] servers = { "127.0.0.1:11211", "192.168.202.128:11211" }; //初始化池 SockIOPool pool = SockIOPool.GetInstance(); pool.SetServers(servers); pool.InitConnections = 3; pool.MinConnections = 3; pool.MaxConnections = 5; pool.SocketConnectTimeout = 1000; pool.SocketTimeout = 3000; pool.MaintenanceSleep = 30; pool.Failover = true; pool.Nagle = false; pool.Initialize(); //客户端实例 MemcachedClient mc = new Memcached.ClientLibrary.MemcachedClient(); mc.EnableCompression = false; mc.Add("aaa", "shit");//添加一个值 mc.Add("bbb", "hello", DateTime.Now.AddSeconds(10));//设置过期时间 mc.Delete("aaa");//删除指定值 mc.Get("aaa"); Console.WriteLine(mc.Get("bbb")); } } }
时间: 2024-10-13 02:40:38