List<string> FoundKeys = new List<string>();
// return false if unable to get SockIO obj
if (pool == null)
{
return FoundKeys;
}
// get all servers and iterate over them
if (servers == null)
servers = pool.Servers;
// if no servers, then return early
if (servers == null || servers.Count <= 0)
{
return FoundKeys;
}
// array of stats Hashtables
Hashtable statsMaps = new Hashtable();
for (int i = 0; i < servers.Count; i++)
{
SockIO sock = pool.GetConnection((string)servers[i]);
if (sock == null)
{
continue;
}
// build command
string command = "stats items/r/n";
try
{
sock.Write(UTF8Encoding.UTF8.GetBytes(command));
sock.Flush();
List<int> itemNUM = new List<int>();
while (true)
{
string line = sock.ReadLine();
if (line.StartsWith(STATS) && line.IndexOf("number") > 0 && line.IndexOf("items") > 0)
{
// STAT items:6:number 4
int index1 = line.IndexOf("items") + 6;
int index2 = line.IndexOf("number") - 1;
int count = int.Parse(line.Substring(index1, index2 - index1));
itemNUM.Add(count);
}
else if (END == line)
{
break;
}
}
foreach (int index in itemNUM)
{
// build command stats cachedump 7 0
string commandCachedump = "stats cachedump " + index.ToString() + " 0/r/n";
sock.Write(UTF8Encoding.UTF8.GetBytes(commandCachedump));
sock.Flush();
while (true)
{
string keyline = sock.ReadLine();
string[] Arr = keyline.Split(' ');
if (Arr.Length > 2 && Arr[0].Equals("ITEM"))
{
string findkey = Arr[1];
if (Arr[1].StartsWith(LikeKey))
{
FoundKeys.Add(findkey);
}
}
else if (END == keyline)
{
break;
}
}
}
}
catch (Exception e)
{
try
{
sock.TrueClose();
}
catch (IOException)
{
if (log.IsErrorEnabled)
{
log.Error(GetLocalizedString("failed to close some socket").Replace("$$Socket$$", sock.ToString()));
}
}
sock = null;
}
if (sock != null)
sock.Close();
}
return FoundKeys;
}