Example #1
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()
        }
Example #2
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();
		}
Example #3
0
        /// <summary>
        /// 获取有效的服务器地址
        /// </summary>
        /// <returns>有效的服务器地</returns>
        public static string[] GetConnectedSocketHost()
        {
            SockIO sock          = null;
            string connectedHost = null;

            foreach (string hostName in serverList)
            {
                if (!string.IsNullOrEmpty(hostName))
                {
                    try
                    {
                        sock = SockIOPool.GetInstance(memCachedConfigInfo.PoolName).GetConnection(hostName);
                        if (sock != null)
                        {
                            connectedHost = hostName + "," + connectedHost;
                        }
                    }
                    finally
                    {
                        if (sock != null)
                        {
                            sock.Close();
                        }
                    }
                }
            }
            return(connectedHost.Split(','));
        }
Example #4
0
 /// <summary>
 /// 受保护类型的缓存对象,初始化一个新的缓存对象
 /// </summary>
 protected MemcacheHelper()
 {
     //读取app.Config中需要缓存的服务器地址信息,可以传递多个地址,使用","分隔
     string[] serverList = ConfigurationManager.AppSettings["Memcached.ServerList"].Split(',');
     try
     {
         var sockIoPool = SockIOPool.GetInstance();
         sockIoPool.SetServers(serverList);
         sockIoPool.InitConnections      = 3;
         sockIoPool.MinConnections       = 3;
         sockIoPool.MaxConnections       = 50;
         sockIoPool.SocketConnectTimeout = 1000;
         sockIoPool.SocketTimeout        = 3000;
         sockIoPool.MaintenanceSleep     = 30;
         sockIoPool.Failover             = true;
         sockIoPool.Nagle = false;
         //实例化缓存对象
         _client = new MemcachedClient();
     }
     catch (Exception ex)
     {
         //错误信息写入事务日志
         throw new Exception(ex.Message);
     }
 }
Example #5
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;
     }
 }
Example #6
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);
        }
Example #7
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;
        }
Example #8
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));
        }
        /// <summary>
        ///
        /// </summary>
        public MemcacheProvider()
        {
            string text = ConfigurationManager.AppSettings["MemcachedHost"];

            if (text != null)
            {
                this.servers = text.ToString().Split(new char[]
                {
                    ','
                });
            }
            this.pool = SockIOPool.GetInstance();
            this.pool.SetServers(this.servers);
            this.pool.InitConnections      = 100;
            this.pool.MinConnections       = 3;
            this.pool.MaxConnections       = 1024;
            this.pool.SocketConnectTimeout = 1000;
            this.pool.SocketTimeout        = 3000;
            this.pool.MaintenanceSleep     = 30L;
            this.pool.Failover             = true;
            this.pool.Nagle = false;
            this.pool.Initialize();
            this.mc = new MemcachedClient
            {
                EnableCompression = false
            };
        }
Example #10
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;
        }
Example #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);
        }
Example #12
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;
            }
        }
Example #13
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
        }
Example #14
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;
        }
Example #15
0
        /// <summary>
        /// 获取有效的服务器地址
        /// </summary>
        /// <returns>有效的服务器地</returns>
        public static string[] GetConnectedSocketHost()
        {
            SockIO sock          = null;
            string connectedHost = null;

            foreach (string hostName in serverList)
            {
                if (!Discuz.Common.Utils.StrIsNullOrEmpty(hostName))
                {
                    try
                    {
                        sock = SockIOPool.GetInstance(memCachedConfigInfo.PoolName).GetConnection(hostName);
                        if (sock != null)
                        {
                            connectedHost = Discuz.Common.Utils.MergeString(hostName, connectedHost);
                        }
                    }
                    finally
                    {
                        if (sock != null)
                        {
                            sock.Close();
                        }
                    }
                }
            }
            return(Discuz.Common.Utils.SplitString(connectedHost, ","));
        }
Example #16
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;
        }
Example #17
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;
        }
        /// <summary>
        /// 获取有效的服务器地址
        /// </summary>
        /// <returns>有效的服务器地</returns>
        public static string[] GetConnectedSocketHost()
        {
            SockIO sock          = null;
            string connectedHost = null;

            foreach (string server in servers)
            {
                if (string.IsNullOrEmpty(server))
                {
                    continue;
                }

                try
                {
                    sock = SockIOPool.GetInstance(sockIOPool.Name).GetConnection(server);
                    if (sock != null)
                    {
                        connectedHost = connectedHost + server;
                    }
                }
                finally
                {
                    if (sock != null)
                    {
                        sock.Close();
                    }
                }
            }

            return(connectedHost.Split(','));
        }
Example #19
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);
        }
Example #20
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;
            }
        }
Example #21
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;
        }
Example #22
0
        public static MemcachedService GetInstance(string inst)
        {
            if (m_isOn)
            {
                return(ms);
            }
            ms      = new MemcachedService();
            ms.mc   = ConfigurationManager.GetSection("memcached") as MemCachedConfig;
            ms.pool = SockIOPool.GetInstance(inst);
            ms.pool.SetServers(ms.mc.serverList.ToArray());
            ms.pool.MinConnections       = ms.mc.minPoolSize;
            ms.pool.MaxConnections       = ms.mc.maxPoolSize;
            ms.pool.SocketConnectTimeout = ms.mc.connectionTimeout;
            ms.pool.SocketTimeout        = ms.mc.socketTimeout;
            ms.pool.Initialize();
            ms.mClient                   = new MemcachedClient();
            ms.mClient.PoolName          = inst;
            ms.mClient.EnableCompression = true;
            m_isOn = true;

            return(ms);

            //String[] serverlist = { "118.194.49.34:11211" };
            //pool = SockIOPool.GetInstance("test");
            //pool.SetServers(serverlist);
            //pool.MinConnections = 3;
            //pool.MaxConnections = 10;
            //pool.SocketConnectTimeout = 2000;
            //pool.SocketTimeout = 10000;
            //pool.Initialize();
            //mClient = new MemcachedClient();
            //mClient.PoolName = "test";
            //mClient.EnableCompression = true;
        }
        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
        }
Example #24
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"
            };
        }
Example #25
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();
        }
Example #26
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;
        }
        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;
        }
Example #28
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);
        }
Example #29
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;
        }
Example #30
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;
            }
        }