剑轩

ServiceStack.Redis删除以某个key开头的数据。获取某个key开头的数量,每个key开头的所有Key

电脑版发表于:2019/6/2 16:39


删除以userkey开头的数据

redis.RemoveByPattern("userkey*");


还可以考虑使用正则表达式删除

redis.RemoveByRegex("正则表达式");


也可以先使用GetAllKeys方法得到所有的key,然后找到你想删除的干掉就行了

redis.GetAllKeys()


每个key开头的所有Key

 IEnumerable<string> keys = redis.GetKeysByPattern("articleDetails_*");


获取某个key开头的数量

int count = redis.GetKeysByPattern("articleDetails_1").Count();

感觉这样有可能key多了会有点影响效率,可以考虑单独使用一个键值对来记录数量

关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢