开发者

Get more than one value from memcache with Ruby

开发者 https://www.devze.com 2023-01-30 06:42 出处:网络
I installed *memcache_client* GEM Ruby from http://s开发者_StackOverflow社区eattlerb.rubyforge.org/memcache-client/

I installed *memcache_client* GEM Ruby from http://s开发者_StackOverflow社区eattlerb.rubyforge.org/memcache-client/

It's easy to get a single value:

cache.get('foo', 'bar')

How to get all values, starting with 'foo', for example foo_1, foo_2, foo_3, foo_* ? Something like "SELECT * FROM foo", but for Memcached.

There will be about 10 000 "foo_n" entries.


Not a perfect solution, but look at the get_multi function:

keys = (1..10_000).map{ |n| "foo_#{n}" }
data = cache.get_multi(*keys)

Unfortunately memcached doesn't support regex key lookups, or even let you get a list of all the keys to process on your own. One alternative would be to use Redis which can get a list of keys using a glob style pattern.


Might want to look at Redis as an alternative to memcache. It supports lists, sets, sorted sets and hashes. http://code.google.com/p/redis/

0

精彩评论

暂无评论...
验证码 换一张
取 消