是否可以通过前缀获取/搜索Memcached密钥? [英] Is it possible to get/search Memcached keys by a prefix?

查看:99
本文介绍了是否可以通过前缀获取/搜索Memcached密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写给memcached很多键/值-> PREFIX_KEY1,PREFIX_KEY2,PREFIX_KEY3

I'm writing to memcached a lot of key/value -> PREFIX_KEY1, PREFIX_KEY2, PREFIX_KEY3

我需要获取所有以PREFIX_开头的密钥.

I need to get all the keys that starts with PREFIX_

有可能吗?

推荐答案

对不起,但没有. Memcached使用一种散列算法,该算法将密钥分布在明显随机的位置,因此这些密钥散布在各处.您必须扫描所有内容才能找到它们.

Sorry, but no. Memcached uses a hashing algorithm that distributes keys at apparently random places, and so those keys are scattered all over. You'd have to scan everything to find them.

此外,您还应该注意,根据设计,memcached可以出于任何原因随时删除任何键.如果要放入东西,则应注意,不能依靠它回来.这对于其原始用例(一种减少数据库命中的缓存)来说绝对不错.但是,如果您想对它做一些更复杂的事情,这可能是一个严重的问题.

Also you should be aware that, by design, memcached can drop any any key at any time for any reason. If you're putting stuff in, you should be aware that you can't depend on it coming back out. This is absolutely fine for its original use case, a cache to reduce hits on a database. But it can be a severe problem if you want to do something more complicated with it.

如果这些限制是一个问题,我建议您改用Redis.它的行为与memcached非常相似,除了它将持久化数据并允许您存储复杂的数据结构.因此,对于您的用例,您可以将哈希存储在Redis中,然后再将整个哈希取出.

If these limitations are a problem, I would suggest that you use Redis instead. It behaves a lot like memcached, except that it will persist data and it lets you store complex data structures. So for your use case you can store a hash in Redis, then pull the whole hash out later.

这篇关于是否可以通过前缀获取/搜索Memcached密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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