|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-25 04:50 UTC] wilfried dot loche at fr dot adp dot com
Description:
------------
Hi,
I use Memcached server via Zend_Cache component. I use a load balanced architecture with 2 web servers (apache).
When I want to delete an item, I expect the delete() method would perform the operation on both servers I put. But it is not the case.
If it makes sense on getting items, to my mind, deletes and updates should be applied on the server pools... no?
Many thx for this great interface,
Wilfried
Reproduce code:
---------------
function getMemcache($port)
{
$memcache = new Memcache;
$memcache->addServer('localhost', $port) or die ('Could not connect #' . $port);
return $memcache;
}
//--- SET !
$memcache = getMemcache(11214);
echo 'add(#11214): '; var_dump($memcache->add('KEY', 'data#11214'));
$memcache = getMemcache(11213);
echo 'add(#11213): '; var_dump($memcache->add('KEY', 'data#11213'));
//--- GET !
$memcache = getMemcache(11214);
echo 'get(#11214): '; var_dump($memcache->get('KEY'));
$memcache = getMemcache(11213);
echo 'get(#11213): '; var_dump($memcache->get('KEY'));
//--- DELETE ALL (try to...)
$memcache = new Memcache;
$memcache->addServer('localhost', 11214) or die ('Could not connect #' . $port);
$memcache->addServer('localhost', 11213) or die ('Could not connect #' . $port);
echo 'delete(#ALL): '; var_dump($memcache->delete('KEY'));
//--- GET !
$memcache = getMemcache(11214);
echo 'get(#11214) => false?: '; var_dump($memcache->get('KEY'));
$memcache = getMemcache(11213);
echo 'get(#11213) => false?: '; var_dump($memcache->get('KEY'));
Expected result:
----------------
add(#11214): bool(true)
add(#11213): bool(true)
get(#11214): string(10) "data#11214"
get(#11213): string(10) "data#11213"
delete(#ALL): bool(true)
get(#11214) => false?: bool(false)
get(#11213) => false?: bool(false)
Actual result:
--------------
add(#11214): bool(true)
add(#11213): bool(true)
get(#11214): string(10) "data#11214"
get(#11213): string(10) "data#11213"
delete(#ALL): bool(true)
get(#11214) => false?: string(10) "data#11214"
get(#11213) => false?: bool(false)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 03:00:01 2025 UTC |
When you add multiple servers to a pool the key is actually only stored on one of them, as determined by the hash strategy. The pool is used for load balancing, not redundancy. Although the memcache.redundancy setting might be of help, if you call ini_set('memcache.redundancy', '2') before you create your pool in the example you will get the result you expected.