Memcache Server存储信息提取

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值