C#/.NET: EnyimMemcached
更新时间:
客户端下载
C#/.NET 代码示例
using System.Net;using Enyim.Caching;using Enyim.Caching.Configuration;using Enyim.Caching.Memcached;namespace OCS.Memcached{public sealed class MemCached{private static MemcachedClient MemClient;static readonly object padlock = new object();//线程安全的单例模式public static MemcachedClient getInstance(){if (MemClient == null){lock (padlock){if (MemClient == null){MemClientInit();}}}return MemClient;}static void MemClientInit(){//初始化缓存MemcachedClientConfiguration memConfig = new MemcachedClientConfiguration();IPAddress newaddress =IPAddress.Parse(Dns.GetHostEntry("your_ocs_host").AddressList[0].ToString());//your_ocs_host替换为OCS内网地址IPEndPoint ipEndPoint = new IPEndPoint(newaddress, 11211);// 配置文件 - ipmemConfig.Servers.Add(ipEndPoint);// 配置文件 - 协议memConfig.Protocol = MemcachedProtocol.Binary;// 配置文件-权限memConfig.Authentication.Type = typeof(PlainTextAuthenticator);memConfig.Authentication.Parameters["zone"] = "";memConfig.Authentication.Parameters["userName"] = "username";memConfig.Authentication.Parameters["password"] = "password";//下面请根据实例的最大连接数进行设置memConfig.SocketPool.MinPoolSize = 5;memConfig.SocketPool.MaxPoolSize = 200;MemClient=new MemcachedClient(memConfig);}}}
依赖
调用代码:MemcachedClient MemClient = MemCached.getInstance();
该文章对您有帮助吗?