c# 遍历memcached
来源:互联网 发布:数据库系统概论 第5版 编辑:程序博客网 时间:2024/05/22 17:21
遍历需要发送cmd命令,模拟telnet的方式获取值。
用到类库:Memcached.ClientLibrary
[TestMethod] public void testMe() { string[] ips = System.Configuration.ConfigurationManager.AppSettings["MemcachedServers"].Split(','); SockIOPool pool = SockIOPool.GetInstance(); pool.SetServers(ips); pool.Initialize(); MemcachedClient client = new MemcachedClient(); client.PrimitiveAsString = true;//加这个参数,可以与其他程序混写缓存 client.EnableCompression = true; SockIO sock = pool.GetConnection("127.0.0.1:11211"); sock.Write(UTF8Encoding.UTF8.GetBytes("stats items \r\n")); sock.Flush(); List<int> listIds = new List<int>(); while (true) { string line = sock.ReadLine(); if (line.StartsWith("END")) { break; } if (line.StartsWith("STAT")) { string[] info = line.Split(' '); string[] tmpid = info[1].Split(':'); int id = int.Parse(tmpid[1]); if (!listIds.Contains(id)) { listIds.Add(id); } } } List<string> listKey = new List<string>(); Hashtable hs = new Hashtable(); foreach (int id in listIds) { sock.Write(UTF8Encoding.UTF8.GetBytes(string.Format("stats cachedump {0} 0 \r\n", id))); sock.Flush(); while (true) { string line = sock.ReadLine(); Debug.WriteLine(line); if (line.StartsWith("END")) { break; } if (line.StartsWith("ITEM")) { string[] info = line.Split(' '); listKey.Add(info[1]); hs.Add(info[1], ""); } } } foreach (string key in listKey) { sock.Write(UTF8Encoding.UTF8.GetBytes(string.Format("get {0} \r\n", key))); sock.Flush(); string value = ""; while (true) { string line = sock.ReadLine(); if (line.StartsWith("END")) { break; } if (!line.StartsWith("VALUE")) { value = line; } } hs[key] = value; } sock.Close(); foreach (DictionaryEntry entry in hs) { Debug.WriteLine("{0}={1}", entry.Key, entry.Value); } }
阅读全文
0 0
- c# 遍历memcached
- Ruby遍历MemCached的key
- 遍历memcached所有的key
- C#使用memcached高速缓存
- C# 操作Memcached
- C# MemCached分布式缓存
- C# Memcached 缓存
- C# Memcached 使用
- memcached维护及其数据遍历实现
- 遍历memcached缓存对象(C#)
- 遍历memcached缓存对象(C#)
- 如何遍历memcached中的item?超级有用
- asp.net(C#)遍历memcached缓存对象
- C#使用memcached实现缓存
- C#使用memcached实现缓存
- C#使用memcached实现缓存
- C#使用memcached实现缓存
- Memcached快递上手之C#
- python 3 爬虫教程
- poj3977Subset (折半枚举)
- PS人物换装--白色换纯色
- lcs
- 算法:插入排序
- c# 遍历memcached
- [leetcode]207. Course Schedule
- 微信小程序 实战小程序实例
- 过滤器-Filter
- 设计模式-6-建造者模式
- 记一次梯子故障后的排查思路
- CSS布局大集合
- LoaderManager使用详解(四)---实例:AppListLoader
- 验证数字的正则表达式