/// <summary><br /> /// 模糊尋找keys,以likekey開頭的key<br /> /// </summary><br /> /// <param name="LikeKey">要找的key</param><br /> /// <returns>返回list</returns><br /> public List<string> FindLikeKey(string LikeKey)<br /> {<br /> return FindLikeKey(null,LikeKey);<br /> }<br /> /// <summary><br /> /// 模糊尋找keys,以likekey開頭的key<br /> /// </summary><br /> /// <param name="servers">伺服器數組</param><br /> /// <param name="LikeKey">要找的key</param><br /> /// <returns>返回list</returns><br /> public List<string> FindLikeKey(ArrayList servers, string LikeKey)<br /> {<br /> // get SockIOPool instance<br /> SockIOPool pool = SockIOPool.GetInstance(_poolName);</p><p> List<string> FoundKeys = new List<string>();<br /> // return false if unable to get SockIO obj<br /> if (pool == null)<br /> {<br /> return FoundKeys;<br /> }</p><p> // get all servers and iterate over them<br /> if (servers == null)<br /> servers = pool.Servers;</p><p> // if no servers, then return early<br /> if (servers == null || servers.Count <= 0)<br /> {<br /> return FoundKeys;<br /> }</p><p> // array of stats Hashtables<br /> Hashtable statsMaps = new Hashtable();</p><p> for (int i = 0; i < servers.Count; i++)<br /> {<br /> SockIO sock = pool.GetConnection((string)servers[i]);<br /> if (sock == null)<br /> {<br /> continue;<br /> }<br /> // build command<br /> string command = "stats items/r/n";<br /> try<br /> {<br /> sock.Write(UTF8Encoding.UTF8.GetBytes(command));<br /> sock.Flush();<br /> List<int> itemNUM = new List<int>();<br /> while (true)<br /> {<br /> string line = sock.ReadLine();<br /> if (line.StartsWith(STATS) && line.IndexOf("number") > 0 && line.IndexOf("items") > 0)<br /> {</p><p> // STAT items:6:number 4<br /> int index1 = line.IndexOf("items") + 6;<br /> int index2 = line.IndexOf("number") - 1;<br /> int count = int.Parse(line.Substring(index1, index2 - index1));<br /> itemNUM.Add(count);<br /> }<br /> else if (END == line)<br /> {<br /> break;<br /> }</p><p> }</p><p> foreach (int index in itemNUM)<br /> {<br /> // build command stats cachedump 7 0<br /> string commandCachedump = "stats cachedump " + index.ToString() + " 0/r/n";<br /> sock.Write(UTF8Encoding.UTF8.GetBytes(commandCachedump));<br /> sock.Flush();<br /> while (true)<br /> {<br /> string keyline = sock.ReadLine();<br /> string[] Arr = keyline.Split(' ');<br /> if (Arr.Length > 2 && Arr[0].Equals("ITEM"))<br /> {<br /> string findkey = Arr[1];<br /> if (Arr[1].StartsWith(LikeKey))<br /> {<br /> FoundKeys.Add(findkey);<br /> }<br /> }<br /> else if (END == keyline)<br /> {<br /> break;<br /> }<br /> }<br /> }<br /> }<br /> catch (Exception e)<br /> {<br /> try<br /> {<br /> sock.TrueClose();<br /> }<br /> catch (IOException)<br /> {<br /> if (log.IsErrorEnabled)<br /> {<br /> log.Error(GetLocalizedString("failed to close some socket").Replace("$$Socket$$", sock.ToString()));<br /> }<br /> }</p><p> sock = null;<br /> }</p><p> if (sock != null)<br /> sock.Close();<br /> }<br /> return FoundKeys;<br /> }