I'm creating some backup CLI script in PHP, which utilize Memcache class, but I have strange problem...
When I attach multiple servers on Memcache, get() method always return false, even if entry exists, but when I attach only one server, in which that entry is placed, its value is returned...
Does not work:
$mc = new Memcache();
$mc->addServer('localhost', 11211);
$mc->addServer('localhost', 11212);
$mc->addServer('localhost', 11213);
var_dump($mc->get('someKey')); //bool(false)
But this works:
$mc = new Memcache();
$mc->addServer('localhost', 11211);
var_dump($mc->get('someKey')); //Outputs actual value
I repeat, I run this script from command line. Entries in memcache were created using Memcache class, too, in situation where all three servers were added into the connection pool. Only difference is that saving of cache entries was tr开发者_如何学编程iggered through HTTP request, using browser.
Any idea?
Try to run this code
<?php
error_reporting(E_ALL || E_NOTICE);
$mc = new Memcache();
$mc->addServer('localhost', 11211);
$mc->addServer('localhost', 11212);
$mc->addServer('localhost', 11213);
var_dump($mc->getExtendedStats());
var_dump($mc->get('someKey')); //bool(false)
?>
Also, you should set()
your key with EXACTLY same server pool as when you get()
it.
精彩评论