php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59805 Key Prefix Strangeness
Submitted: 2011-06-08 16:20 UTC Modified: 2011-06-24 16:46 UTC
From: root at jusme dot org Assigned:
Status: Closed Package: memcached (PECL)
PHP Version: 5.3.6 OS: Linux
Private report: No CVE-ID: None
 [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)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-08 17:40 UTC] root at jusme dot org
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.
 [2011-06-08 17:44 UTC] root at jusme dot org
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"));

?>
 [2011-06-24 15:25 UTC] andrei@php.net
libmemcached < 0.50 had a bug with prefix handling. I just 
released 2.0.0b2 version of the extension that works around 
that bug. Could you install it and see if it fixes your 
problem?
 [2011-06-24 16:46 UTC] root at jusme dot org
Yep, PECL memcached 2.0.0b2 using libmemcached 0.50 has resolved this bug. Marking the ticket as closed since this is no longer an issue with the latest release of PECL memcached.

I've been anxious to try the new PECL memcached 2.0 once it supported libmemcached 0.50. Now that it finally does I can take the new features for a test drive! Thanks for all your effort on this project.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:30 2024 UTC