windows體系使用memcached

1.簡述
memcached官方並不提供原生的donet體系方案,
server端需要在linux環境下編譯成windows下的exe包,
這裏的server端爲1.4.13版本,需要新版本的需要自己編譯,
window體系下,使用memcached做緩存,建議採用“主從架構”,
業務緩存和配置緩存隔離,方便後期對緩存的升級維護優化
2.下載
------server端--------
https://pan.baidu.com/s/1QWxUlDnLkmRUgt_SsqOh7Q
-----client端---------
https://download.csdn.net/download/xuwei_xuwei/10464457


3.安裝server端,4臺服務器cmd執行如下命令


memcached1413.exe  -d runservice -m 1024 -p 11211



4.client端使用


public class MemcachedHelper
    {
        private static string MemcachedBusinessPoolName = "businesspool";
        private static string[] businessList = new string[]{"192.168.100.102:11221", "192.168.100.103:11221" };
        private static string MemcachedConfigPoolName = "configpool";
        private static string[] configList = new string[] { "192.168.100.102:11222", "192.168.100.103:11222" };
        private static MemcachedClient _businessClient;
        private static MemcachedClient _configClient;


        static MemcachedHelper()
        {
            InitBusinessPool();
            _businessClient = new MemcachedClient
            {
                PoolName = MemcachedBusinessPoolName,
                EnableCompression = false
            };
            InitConfigPool();
            _configClient = new MemcachedClient
            {
                PoolName = MemcachedConfigPoolName,
                EnableCompression = false
            };
        }


        private static void InitBusinessPool()
        {
            SockIOPool businesspool = SockIOPool.GetInstance(MemcachedBusinessPoolName);
            businesspool.SetServers(businessList);
            businesspool.InitConnections = 10;
            businesspool.MinConnections = 10;
            businesspool.MaxConnections = 1000;
            businesspool.SocketConnectTimeout = 1000;
            businesspool.SocketTimeout = 3000;
            businesspool.MaintenanceSleep = 30;
            businesspool.Failover = true;
            businesspool.Nagle = false;
            businesspool.Initialize();
        }


        private static void InitConfigPool()
        {
            SockIOPool configpool = SockIOPool.GetInstance(MemcachedConfigPoolName);
            configpool.SetServers(configList);
            configpool.InitConnections = 10;
            configpool.MinConnections = 10;
            configpool.MaxConnections = 1000;
            configpool.SocketConnectTimeout = 1000;
            configpool.SocketTimeout = 3000;
            configpool.MaintenanceSleep = 30;
            configpool.Failover = true;
            configpool.Nagle = false;
            configpool.Initialize();
        }


        public static MemcachedClient GetBusinessClient()
        {
            return _businessClient;
        }


        public static MemcachedClient GetConfigClient()
        {
            return _configClient;
        }
    }    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章