Expiring memcache via regex

旧时模样 提交于 2019-12-10 22:08:13

问题


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

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?


回答1:


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

it sends

  • "stats items"

and than iterate returned items and sends

  • "stats cachedump 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...)



来源:https://stackoverflow.com/questions/11998762/expiring-memcache-via-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!