通过正则表达式使Memcache过期 [英] Expiring memcache via regex

查看:104
本文介绍了通过正则表达式使Memcache过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails应用程序中使用内存缓存.我想说

I'm using memcache in my rails app. I want to say

使用"foo-123- *"之类的键使所有条目失效

expire all the entries with keys like 'foo-123-*'

其中*是任何字符串.当然,没有内存缓存直接支持此功能(对吗?),因为它的构建既简单又快速,因此没有索引.

Where * is any string. Of course, no memcache distribution supports this directly (right?) because it's built to be simple and fast so it doesn't have indexes.

有两个项目通过保留本地密钥列表来解决此问题:

There are a couple projects that sort of address this, by keeping a local list of keys:

  • https://github.com/defconomicron/dalli-store-extensions
  • https://github.com/jkassemi/memcache-store-extensions

但是将列表保存在内存中...该列表可能在应用程序实例之间变得不同步...因此不可靠.

But in keeping the list in memory… that list can become out of sync between application instances… so it's not reliable.

此问题是否已通过其他方式解决?我是否缺少通用解决方案?

Has this problem been solved in another way? Am I missing a common solution?

推荐答案

不可能像您想要的那样查询memcached ...但这是一个我发现返回键列表的php示例

as you said, query memcached like you want is not possible... but here is a php example i found that returns key list

http://snipt.org/xtP

它发送

  • 统计项"

然后迭代返回的项目并发送

and than iterate returned items and sends

  • "stats cachedump 42 100"

42是项目编号,100是要退回的项目数量

42 is item number, 100 is number of items to return

然后,您可以遍历返回的键并删除不再需要的键.

then you can iterate through returned keys and delete keys that you don't need any more.

(但这仍然是一个丑陋的解决方法...)

(but this is an ugly workaround anyway...)

这篇关于通过正则表达式使Memcache过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆