3

I would like to do something like:

memcache.get_multi(ALL, key_prefix='somePrefix_')

in order to read every memcached key with the prefix somePrefix_.

This question asks whether all keys can be found, and this answer to another question offers an undocumented debugging-only method in PHP. However I don't want to cachedump and then find my prefix, it seems kind of hacky - and at any rate I am looking for this to stay in after development.

I tried an empty list of keys, [], thinking that in the spirit of 0 being often used for 'unlimited' it might find them all. Alas, it did not.

I suspect this means it is not possible (as there is no other function to use, and I can't think how else 'all' might be represented) - but I would just like to confirm this as it makes the key_prefix option seem only vaguely useful, in my opinion. (When I saw it in docs, my first thought was "ah neat, I can grab everything with some prefix at once!")

Community
  • 1
  • 1
OJFord
  • 10,522
  • 8
  • 64
  • 98
  • If you are writing your own PHP classes then there's nothing to stop you keeping your own wildcard lists as a memcached variable. But failing this its the tacky cachedump scan. Sorry. – TerryE Jul 30 '14 at 17:20
  • Python*. Yeah, I probably will do that since it's actually even simpler - in this case I know at 'dev-time' how many and what they are. I had hoped for a general solution though. – OJFord Jul 30 '14 at 18:05
  • Typically you write a cache proxy class and use it to do all this housekeeping, then just inherit all this bumf in you individual memcached objects – TerryE Aug 01 '14 at 18:05
  • @TerryE Is it better practice to have some class from which 'lookupString' or 'setString' is called, or to overload `put()` and `get()` in the `db.Model` class? – OJFord Aug 05 '14 at 20:57

1 Answers1

4

Nope, you can only get the item if you know the key.

marcadian
  • 2,608
  • 13
  • 20
  • 2
    In that case, I don't understand why we have `key_prefix` *and* `namespace` keyword arguments. What does `key_prefix` offer beyond the illusion of a new namespace? – OJFord Sep 01 '14 at 21:11
  • @OJFord I think it's just to avoid you having to hard code the same prefix string multiple times – Will Munn Nov 05 '17 at 09:30