using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Memcached.ClientLibrary;
using System.Configuration;
using System.Collections;
namespace MemcachedTest
{
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string MemCachedServer = ConfigurationManager.AppSettings["MemCachedServer"].ToString();
string MemCachedPoolName = ConfigurationManager.AppSettings["MemCachedPoolName"].ToString();
char[] delimeter = { ';', '|', ',' };
string[] serverList = MemCachedServer.Split(delimeter, System.StringSplitOptions.RemoveEmptyEntries);
SockIOPool pool = SockIOPool.GetInstance(MemCachedPoolName);
pool.SetServers(serverList);
pool.Initialize();
MemcachedClient _memClient = new MemcachedClient();
_memClient.PoolName = MemCachedPoolName;
_memClient.CompressionThreshold = long.MaxValue;
_memClient.EnableCompression = false;
IDictionary stats = _memClient.Stats(); //return server list
string strOutput = "Raw Output:<br>";
foreach (string key1 in stats.Keys)
{
//Console.WriteLine(key1);
strOutput += key1 + "<br>";
Hashtable stat = (Hashtable)stats[key1]; // resurn key/value pairs in each server
foreach (string key2 in stat.Keys)
{
//Console.WriteLine(key2 + ":" + values[key2]);
strOutput += key2 + ":" + stat[key2] + "<br>";
}
Console.WriteLine();
strOutput += "<br>";
}
Response.Write(strOutput);
Response.End();
}
}
}
Sample Result:
Raw Output:
10.0.0.1:11211
time:1275546796
total_items:53
connection_structures:7
version:1.2.1
limit_maxbytes:67108864
cmd_get:81
bytes_written:81393
total_connections:64
bytes:2492
get_misses:33
pointer_size:32
uptime:104818
curr_connections:5
pid:1220
bytes_read:3555
get_hits:48
cmd_set:53
curr_items:47
10.0.0.2:11211
time:1275546796
total_items:20
connection_structures:13
version:1.2.1
limit_maxbytes:67108864
cmd_get:19
bytes_written:128016
total_connections:106
bytes:947
get_misses:5
pointer_size:32
uptime:75835
curr_connections:3
pid:4620
bytes_read:3099
get_hits:14
cmd_set:20
curr_items:18
10.0.0.2:11212
time:1275546796
total_items:30
connection_structures:15
version:1.2.1
limit_maxbytes:67108864
cmd_get:44
bytes_written:162382
total_connections:105
bytes:1216
get_misses:8
pointer_size:32
uptime:75831
curr_connections:6
pid:5468
bytes_read:4126
get_hits:36
cmd_set:30
curr_items:23