EnyimMemcached扩展 遍历功能
Memcached本身对外提供的命令不多,也就add、get、set、incr、decr、replace、delete、stats等几个,客户端对这些操作进行了封装,总体来说调用还是很简单的。 初看了下EnyimMemcached结构,所有的操作都从Operation类继承,每个子类都实现自己的ExcuteAction
![]() |
![]() |
|||
| 操作:新窗口查看图片 | ||||
|
||||
![]() |
![]() |
所有的操作都由MemCachedClient这个门面提供
![]() |
![]() |
|||
| 操作:新窗口查看图片 | ||||
|
||||
![]() |
![]() |
在使用过程中,我需要遍历当前缓存,获取所有键值,EnyimMemCached却没有提供遍历的方法。在网上查了下,http://www.cnblogs.com/sunli/archive/2008/11/01/1324153.html 提供了遍历的思路,很简单,用"stats item"与"stats cachedump 1 0"命令即可实现遍历,我要做的只是把两个命令封装成上面提到的Operation,下面是实现代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions; namespace Enyim.Caching.Memcached
{
/// <summary>
/// 扩展的获取所有键值操作 by wm
/// </summary>
internal class CacheDumpOperation : Operation
{
public CacheDumpOperation(ServerPool pool, string regex) : base(pool)
{
this.regexquery = regex;
} private ArrayList results;
/// <summary>
/// 结果键值集合
/// </summary>
public ArrayList Results
{
get { return results; }
} private string regexquery = "";
/// <summary>
/// 查询条件正则表达式
/// </summary>
public string RegexQuery
{
get { return regexquery; }
set { regexquery = value; }
} protected override bool ExecuteAction()
{
List<string> lstParams = new List<string>();
ArrayList arrKeys = new ArrayList(); foreach (MemcachedNode server in this.ServerPool.WorkingServers)
{
using (PooledSocket ps = server.Acquire()) //step1
{
if (ps != null)
{
ps.SendCommand("stats items");
while (true)
{
string line = ps.ReadResponse(); if (String.Compare(line, "END", StringComparison.Ordinal) == )
break; if (line.Length < || String.Compare(line, , "STAT ", , , StringComparison.Ordinal) != )
{
continue;
} string para = line.Split(':')[];
if (!lstParams.Contains(para))
{
lstParams.Add(para);
}
}
} } using (PooledSocket psDump = server.Acquire()) //step2
{
if (psDump != null)
{
foreach (string para in lstParams)
{
psDump.SendCommand(string.Format("stats cachedump {0} {1}", para, ));
while (true)
{
string lineDump = psDump.ReadResponse();
if (String.Compare(lineDump, "END", StringComparison.Ordinal) == )
break; if (lineDump.Length < || String.Compare(lineDump, , "ITEM ", , , StringComparison.Ordinal) != )
{
continue;
} string key = lineDump.Split(' ')[];
if (this.regexquery == "")
{
arrKeys.Add(key);
}
else
{
if (Regex.IsMatch(key, this.regexquery))
{
arrKeys.Add(key);
}
}
}
}
}
} } this.results = arrKeys; return true; }
}
}
</string></string>
在MemcachedClient中添加方法
/// <summary>
/// 获取所有键值集合
/// </summary>
/// <returns></returns>
public System.Collections.ArrayList GetKeys()
{
using (CacheDumpOperation g = new CacheDumpOperation(this.pool, ""))
{
g.Execute();
return g.Results;
}
} /// <summary>
/// 根据正则查找匹配缓存键值集合
/// </summary>
/// <param name="regex">
/// <returns></returns>
public System.Collections.ArrayList GetKeys(string regex)
{
using (CacheDumpOperation g = new CacheDumpOperation(this.pool, regex))
{
g.Execute();
return g.Results;
}
}
EnyimMemcached扩展 遍历功能的更多相关文章
- BrnShop开源网上商城第六讲:扩展视图功能
在正式讲解扩展视图功能以前,我们有必要把视图的工作原理简单说明下.任何一个视图都会被翻译成一个c#类,并保存到指定的位置,然后被编译.这也就是为什么能在视图中包含c#代码片段的原因.下面我们通过一个项 ...
- 关于ligerui 中 grid 表格的扩展搜索功能在远程数据加载时无法使用的解决办法
要想使用grid里的扩展搜索功能,除了要引用ligerui主要的js文件外,还必须引入下面的JS文件: 1.Source\demos\filter\ligerGrid.showFilter.js 2. ...
- Java基础知识强化之集合框架笔记17:List集合的特有的遍历功能
1. List集合的特有遍历功能: size()和 get()方法结合使用 2. 代码示例: package cn.itcast_03; import java.util.ArrayList; imp ...
- php扩展Redis功能
php扩展Redis功能 1 首先,查看所用php编译版本V6/V9 在phpinfo()中查看 2 下载扩展 地址:https://github.com/nicolasff/phpredis/dow ...
- DEVOPS技术实践_17:Jenkins使用扩展邮件功能发送邮件
一 环境准备 1.1 安装插件Email Extension 系统管理-管理插件-安装Email Extension插件 1.2 配置 配置jenkins邮箱的全局配置:系统管理-系统设置-完成邮箱配 ...
- 利用Mixins扩展类功能
8.18 利用Mixins扩展类功能 - python3-cookbook 3.0.0 文档 https://python3-cookbook.readthedocs.io/zh_CN/latest/ ...
- 适用于 Windows 的虚拟机扩展和功能
Azure 虚拟机扩展是小型应用程序,可在Azure 虚拟机上提供部署后配置和自动化任务. 例如,如果虚拟机要求安装软件.防病毒保护或进行 Docker 配置,便可以使用 VM 扩展来完成这些任务. ...
- 基于web的网上书城系统开发-----登录注册扩展-------验证码功能
public class CheckCode extends HttpServlet { private static final long serialVersionUID = 1L; privat ...
- 新增扩展程序功能打包提交新版 WARNING ITMS-90473 警告问题
1.问题描述 自从在主应用中加入SiriShortCut功能之后,打包程序上传至 iTunes Connect 就会出现警告,看其原因描述是CFBundleVersion主应用与子应用的不一致导致的 ...
随机推荐
- hdu 5610 Baby Ming and Weight lifting
Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the weight of which c ...
- SQL Server 中使用参数化Top语句
在T-Sql中,一般top数据不确定的情况下,都是拼sql,这样无论是效率还是可读性都不好.应该使用下面参数化Top方式:declare @TopCount int set @TopCount = 1 ...
- 让magento的validate验证hidden field
Object.extend(Validation, { isVisible : function(elm) { return true; }, insertAdvice : function(elm, ...
- Unity 人物跟谁手指的移动(第一种方式)
长夜漫漫无心睡眠,敲敲代码,越敲越来劲! 我发现好多小朋友都在玩熊出没之xxxx这个游戏,居然打了一下午都没玩通第2关,我把测试也叫来陪我一起玩! 结果他也打不通,我再去叫策划,他也没打过,我去叫主管 ...
- IOS开发之---触摸和手势
Touch:在与设备的多点触摸屏交互时生成. 响应者对象 响应者对象就是可以响应事件并对事件作出处理.在iOS中,存在UIResponder类,它定义了响应者对象的所有方法.UIApplication ...
- 性能优化之Hibernate缓存讲解、应用和调优
JavaMelody——一款性能监控.调优工具, 通过它让我觉得项目优化是看得见摸得着的,优化有了针对性.而无论是对于分布式,还是非分布,缓存是提示性能的有效工具. 数据层是EJB3.0实现的,而EJ ...
- Android系统Surface机制的SurfaceFlinger服务简要介绍和学习计划
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8010977 前面我们从Android应用程序与 ...
- HTTP请求的TCP瓶颈分析[转]
阅读目录 延迟的因素 速度延时 带宽延时 最后一公里延时-tracerouter 目标 rwnd的设置 慢启动过程 慢启动的影响 慢启动对HTTP影响的一次计算 拥塞窗口的合适值 服务器配置调优 应用 ...
- Windows下配置sphinx+reStructuredText详解
最近有朋友想在windows下做个人笔记,没有找到顺手的工具,问我有什么好的工具推荐.正好前两天在网上看到一款做文档的利器sphinx+reStructText,当时在ubuntu下搭了下环境试了试, ...
- 监控代码运行时长 -- StopWatch用法例程
在.net环境下,精确的测量出某段代码运行的时长,在网络通信.串口通信以及异步操作中很有意义.现在做了简单的总结.具体代码如下: (1).首先 using System.Diagnostics; (2 ...





