Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        static MemcachedHelper()
        {
            string servers = "Memcached.Servers".GetAppSetting();

            string[] serverList = new string[] { servers };
            if (servers.Contains(","))
            {
                serverList = servers.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }

            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverList);
            pool.InitConnections      = serverList.Length;
            pool.MinConnections       = serverList.Length;
            pool.MaxConnections       = 100;
            pool.SocketConnectTimeout = 1000;
            pool.SocketTimeout        = 3000;
            pool.MaintenanceSleep     = 30;
            pool.Failover             = true;
            pool.Nagle = false;
            pool.Initialize();

            mClient = new MemcachedClient();
            mClient.EnableCompression = false;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //就是构建了一个集群 安装memcached 的使用 我们是一个客户端使用
            //在实际项目中使用 可以在哪些地方使用 有一个唯一的KeyValue 来获取一个单独的数据
            //项目中玩耍的东西。。
            string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" };

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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 MemcachedClient();

            mc.EnableCompression = false;

            Console.WriteLine("------------测  试-----------");
            mc.Set("test", "my value"); //存储数据到缓存服务器,这里将字符串"my value"缓存,key 是"test"

            if (mc.KeyExists("test"))   //测试缓存存在key为test的项目
            {
                Console.WriteLine("test is Exists");
                Console.WriteLine(mc.Get("test").ToString());  //在缓存中获取key为test的项目
            }
            else
            {
                Console.WriteLine("test not Exists");
            }

            Console.ReadLine();

            mc.Delete("test");  //移除缓存中key为test的项目

            if (mc.KeyExists("test"))
            {
                Console.WriteLine("test is Exists");
                Console.WriteLine(mc.Get("test").ToString());
            }
            else
            {
                Console.WriteLine("test not Exists");
            }
            Console.ReadLine();

            SockIOPool.GetInstance().Shutdown();  //关闭池, 关闭sockets
        }
Ejemplo n.º 3
0
        public MemCache(string[] strServer, string pre)
        {
            preFix = pre;
            try
            {
                pool = SockIOPool.GetInstance();
                pool.SetServers(strServer);

                //初始化连接数
                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();
            }
            catch (Exception ex)
            {
                //TODO 记录日志
                throw ex;
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //分布Memcachedf服务IP 端口
            string[] servers = { "10.12.11.44: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("keyddd", "sssssssss");

            mc.Add("ssss", "dddd", DateTime.Now.AddDays(1));

            //mc.Delete()
            //mc.Set()
        }
Ejemplo n.º 5
0
        static MemcacheHelper()
        {
            string[] serverlist = { "60.18.162.202:11211" };//一定要将地址写到Web.config文件中。
            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();

            // 获得客户端实例
            mc = new MemcachedClient();
            mc.EnableCompression = false;
        }
Ejemplo n.º 6
0
        public MemCacheTools_V2(string[] server)
        {
            serverlist = server;
            pool       = SockIOPool.GetInstance();
            pool.SetServers(serverlist);      //添加服务器列表
            pool.InitConnections      = 3;    //设置连接池初始数目
            pool.MinConnections       = 3;    //设置最小连接数目
            pool.MaxConnections       = 5;    //设置最大连接数目
            pool.SocketConnectTimeout = 1000; //设置连接的套接字超时。
            pool.SocketTimeout        = 3000; //设置套接字超时读取
            pool.MaintenanceSleep     = 30;   //设置维护线程运行的睡眠时间。如果设置为0,那么维护线程将不会启动;
            //获取或设置池的故障标志。
            //如果这个标志被设置为true则socket连接失败,
            //将试图从另一台服务器返回一个套接字如果存在的话。
            //如果设置为false,则得到一个套接字如果存在的话。否则返回NULL,如果它无法连接到请求的服务器。
            pool.Failover = true;
            //如果为false,对所有创建的套接字关闭Nagle的算法。
            pool.Nagle = false;
            pool.Initialize();
            string     name     = serverlist[0];
            SockIOPool pooltemp = SockIOPool.GetInstance(serverlist[0]);

            pooltemp.SocketTimeout        = 10000;
            pooltemp.SocketConnectTimeout = 5000;
            pooltemp.SetServers(serverlist);
            pooltemp.Initialize();
            if (!memcacheList.Contains(name))
            {
                memcacheList.Add(name);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 初始化MemCache
        /// </summary>
        private static void InitMemCached()
        {
            memClient = new MemcachedClient();
            if (poolName.Trim() == "")
            {
                return;
            }
            if (sockPool == null)
            {
                //初始化池
                sockPool = SockIOPool.GetInstance(poolName);
                sockPool.SetServers(serverList);

                sockPool.InitConnections = 2;
                sockPool.MinConnections  = 10;
                sockPool.MaxConnections  = 10000;

                sockPool.SocketConnectTimeout = 1000;
                sockPool.SocketTimeout        = 3000;

                sockPool.MaintenanceSleep = 30;
                sockPool.Failover         = true;

                sockPool.Nagle = false;
                sockPool.Initialize();

                // 获得客户端实例
                MClient.PoolName = poolName;
                //是否数据压缩
                MClient.EnableCompression = false;
            }
        }
        SockIOPool IMemcachedClientConfiguration.CreatePool()
        {
            try
            {
                string[] servers = this.Servers
                                   .Select(ip => ip.Address.ToString() + ":" + ip.Port)
                                   .ToArray();

                SockIOPool pool = SockIOPool.GetInstance(this.SocketPool.Name);
                pool.SetServers(servers);
                pool.InitConnections      = this.SocketPool.IniSize;
                pool.MinConnections       = this.SocketPool.MinSize;
                pool.MaxConnections       = this.SocketPool.MaxSize;
                pool.SocketConnectTimeout = this.SocketPool.ConnectionTimeout.Milliseconds;
                pool.SocketTimeout        = this.SocketPool.SocketTimeout.Milliseconds;
                pool.MaintenanceSleep     = this.SocketPool.MaintenanceSleep.Milliseconds;
                pool.Failover             = this.SocketPool.IsFailOver;
                pool.Nagle            = this.SocketPool.IsNagle;
                pool.HashingAlgorithm = HashingAlgorithm.NewCompatibleHash;
                pool.Initialize();

                return(pool);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 9
0
        private MemcachedClientSatat(String[] servers, string poolName)
        {
            string msgnumstr = ConfigurationSettings.AppSettings["msgnum"];

            msgnum = msgnumstr == null ? 0 : int.Parse(msgnumstr);
            string keystr = ConfigurationSettings.AppSettings["analyzedkey"];

            if (keystr != null)
            {
                analyzedkey = keystr;
            }
            this.serverlist = servers;
            // initialize the pool for memcache servers
            try
            {
                pool = SockIOPool.GetInstance(poolName);
            }
            catch (Exception)
            {
                throw;
            }
            pool.SetServers(serverlist);
            pool.Initialize();
            mc                   = new MemcachedClient();
            mc.PoolName          = poolName;
            mc.EnableCompression = false;
        }
Ejemplo n.º 10
0
        public static void MemcachedPoolinitialize(string servers)
        {
            char[]   separator  = { ',' };
            string[] serverlist = servers.Split(separator);

            // initialize the pool for memcache servers
            try
            {
                SockIOPool pool = SockIOPool.GetInstance();
                if (pool != null)
                {
                    pool.SetServers(serverlist);

                    pool.InitConnections = 3;
                    pool.MinConnections  = 3;
                    pool.MaxConnections  = 50;

                    pool.SocketConnectTimeout = 1000;
                    pool.SocketTimeout        = 3000;

                    pool.MaintenanceSleep = 30;
                    pool.Failover         = true;
                    pool.Nagle            = false;
                    pool.Initialize();
                }
            }
            catch (Exception ex)
            {
                log.Fatal(ex, "MemcachedPoolinitialize error");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 自动货源切换管理服务
        /// </summary>
        static void Main()
        {
            SockIOPool pool2 = SockIOPool.GetInstance("Price_Cache");

            string[] serverlist2 = ConfigurationManager.AppSettings["ServerList2"].Split(',');
            pool2.SetServers(serverlist2);
            pool2.SetWeights(new int[] { 1 });
            pool2.InitConnections      = 5;
            pool2.MinConnections       = 5;
            pool2.MaxConnections       = 280;
            pool2.MaxIdle              = 1000 * 60 * 60 * 6;
            pool2.SocketTimeout        = 1000 * 3;
            pool2.SocketConnectTimeout = 0;
            pool2.SocketTimeout        = 3000;
            pool2.MaintenanceSleep     = 60;
            pool2.Failover             = true;
            pool2.Nagle   = false;
            pool2.MaxBusy = 1000 * 10;
            pool2.Initialize();

            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Service1()
            };
            ServiceBase.Run(ServicesToRun);
        }
Ejemplo n.º 12
0
        static MemcacheHelper()
        {
            //string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" };//should in config。
            string[] serverlist = ConfigurationManager.AppSettings["MemcacheConfig"].Split(',');

            //init pool
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();

            // get client instance
            mc = new MemcachedClient();
            mc.EnableCompression = false;
        }
Ejemplo n.º 13
0
        static MemcacheHelper()
        {
            //最好放在配置文件中
            string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" };

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();

            // 获得客户端实例
            mc = new MemcachedClient();
            mc.EnableCompression = false;
        }
Ejemplo n.º 14
0
		public static void Main(string[] args) 
		{
			String[] serverlist = { "140.192.34.72:11211", "140.192.34.73:11211"  };

			// initialize the pool for memcache servers
			SockIOPool pool = SockIOPool.GetInstance("test");
			pool.SetServers(serverlist);
			pool.Initialize();

			mc = new MemcachedClient();
			mc.PoolName = "test";
			mc.EnableCompression = false;

			test1();
			test2();
			test3();
			test4();
			test5();
			test6();
			test7();
			test8();
			test9();
			test10();
			test11();
			test12();
			test13();
			test14();

			pool.Shutdown();
		}
Ejemplo n.º 15
0
 //初始化缓存
 static void MemClientInit()
 {
     try
     {
         MemClient = CallContext.GetData("client") as MemcachedClient;
         if (MemClient == null)
         {
             string   strAppMemcachedServer = System.Configuration.ConfigurationManager.AppSettings["MemcachedServerList"];
             string[] servers = strAppMemcachedServer.Split(',');
             //初始化池
             SockIOPool pool = SockIOPool.GetInstance();
             pool.SetServers(servers);
             pool.InitConnections      = 3;
             pool.MinConnections       = 3;
             pool.MaxConnections       = 5000;
             pool.SocketConnectTimeout = 1000;
             pool.SocketTimeout        = 3000;
             pool.MaintenanceSleep     = 30;
             pool.Failover             = true;
             pool.Nagle = false;
             pool.Initialize();
             //客户端实例
             MemClient = new MemcachedClient();
             MemClient.EnableCompression = false;
             CallContext.SetData("client", MemClient);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// session构造函数
        /// </summary>
        /// <param name="strServer">服务器</param>
        /// <param name="sessionHour">session保存时间,单位为小时</param>
        /// <param name="cookieDomain">给cookie指定域名,用于跨域访问</param>
        public MySession(string[] strServer, int sessionHour, string cookieDomain, string pre)
        {
            mc                = new MemcachedClient();
            preFix            = pre;
            this.sessionHour  = sessionHour;
            this.cookieDomain = cookieDomain;
            pool              = SockIOPool.GetInstance();
            pool.SetServers(strServer);

            //初始化连接数
            pool.InitConnections = 3;
            //最小连接数
            pool.MinConnections = 3;
            //最大连接数
            pool.MaxConnections = 20;

            pool.SocketConnectTimeout = 1000;
            pool.SocketTimeout        = 3000;

            pool.MaintenanceSleep = 30;
            pool.Failover         = true;

            pool.Nagle = false;
            pool.Initialize();
        }
Ejemplo n.º 17
0
        public MemcacheWriter()
        {
            //分布Memcachedf服务IP 端口
            //string[] servers = { "192.168.1.100:11211", "192.168.1.2:11211" };
            string strAppMemcachedServer = System.Configuration.ConfigurationManager.AppSettings["MemcachedServerList"];

            string[] servers = strAppMemcachedServer.Split(',');
            //初始化池
            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;
            memcachedClient      = mc;
        }
Ejemplo n.º 18
0
        private void start(params string[] servers)
        {
            string[] serverlist;
            if (servers == null || servers.Length < 1)
            {
                serverlist = new string[] { "127.0.0.1:11011" }; //服务器列表,可多个
            }
            else
            {
                serverlist = servers;
            }
            pool = SockIOPool.GetInstance();

            //根据实际情况修改下面参数
            pool.SetServers(serverlist);
            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(); // initialize the pool for memcache servers
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            //分布Memcachedf服务IP 端口
            string[] servers = { "192.168.1.9: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("key1", "This is my value", DateTime.Now.AddMinutes(20));
        }
Ejemplo n.º 20
0
        static MemcacheHelper()
        {
            //最好放在配置文件中
            //string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" };
            string strMemcacheServerlist = ConfigHelper.GetAppSettings("MemcacheServerlist");

            if (string.IsNullOrEmpty(strMemcacheServerlist))
            {
                throw new Exception("未在配置文件的<AppSettings>下配置MemcacheServerlist;eg:<add key=\"MemcacheServerlist\" value=\"127.0.0.1:11211, 10.0.0.132:11211\" />");
            }
            string[] serverlist = strMemcacheServerlist.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();

            // 获得客户端实例
            mc = new MemcachedClient();
            mc.EnableCompression = false;
        }
Ejemplo n.º 21
0
        static MemcacheWriter()
        {
            string strAppMemcache = System.Configuration.ConfigurationManager.AppSettings["MemcachedServerList"];

            if (string.IsNullOrEmpty(strAppMemcache))
            {
                throw new Exception("Mencache配置文件未配置!");
            }
            string[] serverlist = strAppMemcache.Split(',');

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();

            // 获得客户端实例
            mc = new MemcachedClient();
            mc.EnableCompression = false;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 入口
        /// </summary>
        /// <returns></returns>
        public static CompanyRightCached getInstance()
        {
            if (_objInstance == null)
            {
                lock (_object)
                {
                    if (_objInstance == null)
                    {
                        _objInstance = new CompanyRightCached();
                        //initialize the pool for memcache servers
                        SockIOPool pool = SockIOPool.GetInstance("CompanyRightCached");

                        string cServerList = System.Configuration.ConfigurationManager.AppSettings["MemcachedServerList"] == null ?
                                             string.Empty : System.Configuration.ConfigurationManager.AppSettings["MemcachedServerList"];
                        if (cServerList != string.Empty)
                        {
                            _serverlist = cServerList.Split(',');
                        }
                        pool.SetServers(_serverlist);
                        pool.Initialize();

                        _mc                   = new MemcachedClient();
                        _mc.PoolName          = "CompanyRightCached";
                        _mc.EnableCompression = false;
                    }
                }
            }
            return(_objInstance);
        }
Ejemplo n.º 23
0
        static MemcacheHelper()
        {
            //最好放在配置文件中
            string localIP = ComputerHelper.GetLocalIP();

            string[] serverList = { localIP + ":11211", "10.0.0.137:11211" };

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverList);

            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();

            //获得客户端实例
            m_memcachedClient = new MemcachedClient();
            m_memcachedClient.EnableCompression = false;
        }
Ejemplo n.º 24
0
        public bool MemcacheClientInit()
        {
            this.nosqlTb.Text += "MemcacheClient Init Started!\r\n";

            string[] serverlist = { "127.0.0.1:11211", "90.0.12.120:11211" };

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();
            this.nosqlTb.Text += "MemcacheClient Init End!\r\n";
            return(true);
        }
Ejemplo n.º 25
0
        static object LOCK_OBJECT = new object();//安全锁定
        /// <summary>
        /// 静态构造函数
        /// </summary>
        static MemcachedHelper()
        {
            InitServer();
            foreach (var k in Servers.Keys)
            {
                SockIOPool pool = SockIOPool.GetInstance(k);
                string[]   s    = { Servers[k] };
                pool.SetServers(s);//设置服务器
                pool.MaxConnections       = 10000;
                pool.MinConnections       = 10;
                pool.SocketConnectTimeout = 1000;
                pool.SocketTimeout        = 100;
                pool.Initialize();//初始化缓存线程池
            }
            //默认池
            SockIOPool defaultPool = SockIOPool.GetInstance("DefaultPool");

            defaultPool.SetServers(Servers.Keys.Select(k => Servers[k]).ToArray());//设置服务器
            defaultPool.MaxConnections       = 10000;
            defaultPool.MinConnections       = 10;
            defaultPool.SocketConnectTimeout = 1000;
            defaultPool.SocketTimeout        = 100;
            defaultPool.Initialize(); //初始化默认线程池
            mc = new MemcachedClient {
                PoolName = "DefaultPool"
            };
        }
Ejemplo n.º 26
0
        public MemcachedCache()
        {
            foreach (string info in (WebConfig.GetApp("MemcachedCache.MemcachedServer") ?? string.Empty).Split(';'))
            {
                if (!string.IsNullOrEmpty(info.Trim()))
                {
                    memcachedServer.Add(info);
                }
            }

            if (pool.IsNull() && memcachedServer.Count > 0)
            {
                pool = SockIOPool.GetInstance();
                pool.SetServers(memcachedServer);

                pool.InitConnections      = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.InitConnections") ?? "3");
                pool.MinConnections       = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.MinConnections") ?? "3");
                pool.MaxConnections       = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.MaxConnections") ?? "5");
                pool.SocketConnectTimeout = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.SocketConnectTimeout") ?? "1000");
                pool.SocketTimeout        = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.SocketTimeout") ?? "3000");
                pool.MaintenanceSleep     = Convert.ToInt32(WebConfig.GetApp("MemcachedCache.MaintenanceSleep") ?? "30");
                pool.Failover             = (WebConfig.GetApp("MemcachedCache.Failover") ?? "") == "true" ? true : false;
                pool.Nagle = (WebConfig.GetApp("MemcachedCache.Nagle") ?? "") == "true" ? true : false;
                //pool.HashingAlgorithm = HashingAlgorithm.NewCompatibleHash;
                pool.Initialize();

                mc                   = new MemcachedClient();
                mc.PoolName          = WebConfig.GetApp("MemcachedCache.PoolName") ?? "default";
                mc.EnableCompression = (WebConfig.GetApp("MemcachedCache.EnableCompression") ?? "") == "true" ? true : false;
            }
        }
Ejemplo n.º 27
0
        static MemCacheHelper()
        {
            //string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" };//定义到Web.config
            //string serName = ConfigurationManager.AppSettings["MemCacheFirst"];
            string[] serverlist = { serName };
            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();

            // 获得客户端实例
            mc = new MemcachedClient();
            mc.EnableCompression = false;
        }
Ejemplo n.º 28
0
        public MemcachedWriter()
        {
            //初始化memcached
            //分布Memcachedf服务IP 端口
            string[] servers = System.Configuration.ConfigurationManager.AppSettings["MemcachedAddress"].Split(',');;
            //string[] servers = { "192.168.5.19: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 mc1 = new MemcachedClient();

            mc1.EnableCompression = false;

            mc = mc1;
        }
Ejemplo n.º 29
0
        public static MemcachedClient GetCurrentMemClient2()
        {
            if (client == null)
            {
                string   strAppMemcachedServer = System.Configuration.ConfigurationManager.AppSettings["MemcachedServerList"];
                string[] servers = strAppMemcachedServer.Split(',');
                //初始化池
                SockIOPool pool = SockIOPool.GetInstance();
                pool.SetServers(servers);
                pool.InitConnections      = 3;
                pool.MinConnections       = 3;
                pool.MaxConnections       = 500;
                pool.SocketConnectTimeout = 1000;
                pool.SocketTimeout        = 3000;
                pool.MaintenanceSleep     = 30;
                pool.Failover             = true;
                pool.Nagle = false;
                pool.Initialize();
                //客户端实例
                client = new MemcachedClient();
                client.EnableCompression = false;
            }

            return(client);
        }
Ejemplo n.º 30
0
        static MemcacheHelper()
        {
            string[] serverlist = new string[] { ConfigurationManager.AppSettings["MemcacheAddress"] };

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);

            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();

            // 获得客户端实例
            mc = new MemcachedClient();
            mc.EnableCompression = false;
        }
Ejemplo n.º 31
0
        private static void CreateManager()
        {
            serverList = Utils.SplitString(memCachedConfigInfo.ServerList, ",");

            pool = SockIOPool.GetInstance(memCachedConfigInfo.PoolName);
            pool.SetServers(serverList);
            pool.InitConnections = memCachedConfigInfo.IntConnections;//初始化链接数
            pool.MinConnections = memCachedConfigInfo.MinConnections;//最少链接数
            pool.MaxConnections = memCachedConfigInfo.MaxConnections;//最大连接数
            pool.SocketConnectTimeout = memCachedConfigInfo.SocketConnectTimeout;//Socket链接超时时间
            pool.SocketTimeout = memCachedConfigInfo.SocketTimeout;// Socket超时时间
            pool.MaintenanceSleep = memCachedConfigInfo.MaintenanceSleep;//维护线程休息时间
            pool.Failover = memCachedConfigInfo.FailOver; //失效转移(一种备份操作模式)
            pool.Nagle = memCachedConfigInfo.Nagle;//是否用nagle算法启动socket
            pool.HashingAlgorithm = HashingAlgorithm.NewCompatibleHash;
            pool.Initialize();            

            mc = new MemcachedClient();
            mc.PoolName = memCachedConfigInfo.PoolName;
            mc.EnableCompression = false;
        }