|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-06-08 16:20 UTC] root at jusme dot org
Description:
------------
Running two different Memcached "domains" using the same memcached server, can't retrieve the same key from each domain.
I assumed that the final key would be Memcached::OPT_PREFIX_KEY concatenated with the key (i.e. $key = Memcached::OPT_PREFIX_KEY . $key). I also tried the test case assuming an implicit underscore (i.e. $key = Memcached::OPT_PREFIX_KEY . "_" . $key) just in case there was some weirdness there since the documentation examples don't use an underscore (not that it matters either way since it's supposed to be transparent to the user).
Is there something else going on with the Memcached::OPT_PREFIX_KEY that should be documented in case people want to access keys across multiple "domains"?
Reproduce code:
---------------
<?
$mc = new Memcached("id1");
$mc->setOption(Memcached::OPT_PREFIX_KEY, "namespace1_");
$mc->addServer("127.0.0.1", 11211);
$mc->set("foo", "bar");
var_dump($mc->get("foo"));
$mc = new Memcached("id1");
var_dump($mc->getOption(Memcached::OPT_PREFIX_KEY));
var_dump($mc->get("foo"));
$mc2 = new Memcached("id2");
$mc2->addServer("127.0.0.1", 11211);
var_dump($mc2->getOption(Memcached::OPT_PREFIX_KEY));
var_dump($mc2->get("namespace1_foo"));
?>
Expected result:
----------------
string(3) "bar"
string(11) "namespace1_"
string(3) "bar"
string(0) ""
string(3) "bar"
Actual result:
--------------
string(3) "bar"
string(11) "namespace1_"
string(3) "bar"
string(0) ""
bool(false)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
Just to be clear, removing all lines in the reproduce code with Memcached::OPT_PREFIX_KEY and removing the prefix from the key on the last line (which becomes var_dump($mc2->get("foo"));) works as expected.And for completeness, this code works as expected: <? $mc = new Memcached("id1"); $mc->setOption(Memcached::OPT_PREFIX_KEY, "namespace1_"); $mc->addServer("127.0.0.1", 11211); $mc->set("foo", "bar"); var_dump($mc->get("foo")); $mc = new Memcached("id1"); var_dump($mc->getOption(Memcached::OPT_PREFIX_KEY)); var_dump($mc->get("foo")); $mc2 = new Memcached("id2"); $mc2->setOption(Memcached::OPT_PREFIX_KEY, "namespace1_"); $mc2->addServer("127.0.0.1", 11211); var_dump($mc2->get("foo")); ?>