/// <summary>
/// 静态构造函数
/// </summary>
static MemcacheHelper()
{
InitServer();
List<string> keys = Servers.Keys.ToList<string>();
以下这段foreach 是用来做什么的。不太明白。请大虾解释下。
foreach (var k in Servers.Keys)
{
SockIOPool pool = SockIOPool.GetInstance(k);
string[] s = new string[] { Servers[k] };
pool.SetServers(s);//设置服务器
pool.MaxConnections = 10000;
pool.MinConnections = 10;
pool.SocketConnectTimeout = 1000;
pool.SocketTimeout = 100;
pool.Initialize();//初始化缓存线程池
}
//以下这段代码与上面有什么区别呢?请大虾解释下?
//默认池
List<string> defaultServerList=new List<string>();
foreach (var k in Servers.Keys) defaultServerList.Add(Servers[k]);
SockIOPool defaultPool = SockIOPool.GetInstance("DefaultPool");
defaultPool.SetServers(defaultServerList.ToArray());//设置服务器
defaultPool.MaxConnections = 10000;
defaultPool.MinConnections = 10;
defaultPool.SocketConnectTimeout = 1000;
defaultPool.SocketTimeout = 100;
defaultPool.Initialize(); //初始化默认线程池
mc = new MemcachedClient();
mc.PoolName = "DefaultPool";
}
/// <summary>
/// 初始化服务器列表,这里默认两台服务器.
/// </summary>
static void InitServer(){
//这里可以写复杂灵活点,动态从配置文件获取,我这里固定了两个
Servers.Add("Svr1", ConfigurationManager.AppSettings["Svr1"]);
Servers.Add("Svr2", ConfigurationManager.AppSettings["Svr2"]);
}
看起来
上面的是一个一个配置
下面的是一次性配置