上云无忧 > 文档中心 > 天翼云分布式缓存服务Memcache连接方式(C#/.NET: EnyimMemcached)
分布式缓存服务Memcache
天翼云分布式缓存服务Memcache连接方式(C#/.NET: EnyimMemcached)

文档简介:
C#/.NET代码示例 namespace ECS.Memcached { public sealed class MemCached { private static MemcachedClient MemClient; static readonly object padlock = new object(); //线程安全的单例模式 public static MemcachedClient getInstance()
*产品来源:中国电信天翼云。免费试用 咨询热线:400-826-7010,为您提供专业的售前咨询,让您快速了解云产品,助您轻松上云! 微信咨询
  免费试用、价格特惠

C#/.NET: EnyimMemcached


C#/.NET代码示例

namespace ECS.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_ecs_host").AddressList[0].ToString());//your_ecs_host替换为ECS内网地址
            IPEndPoint ipEndPoint = new IPEndPoint(newaddress, 11211);
              // 配置文件 - ip
            memConfig.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);
                  }
          }
}

相似文档
官方微信
联系客服
400-826-7010
7x24小时客服热线
分享
  • QQ好友
  • QQ空间
  • 微信
  • 微博
返回顶部