note 115665 added to memcached.getmulti

From: Date: Thu, 04 Sep 2014 23:58:05 +0000
Subject: note 115665 added to memcached.getmulti
Groups: php.notes 
Request: Send a blank email to php-notes+get-200369@lists.php.net to get a copy of this message
GOTCHA: Recently I was tasked with moving from PECL memcache to PECL memcached and ran into a major problem -- memcache and memcached serialize data differently, meaning that data written with one library can't necessarily be read with the other library. For example, If you write an object or an array with memcache, it's interpreted as an integer by memcached. If you write it with memcached, it's interpreted as a string by memcache. tl;dr - You can't safely switch between memcache and memcached without a either a cache flush or isolated cache environments. <?php $memcache = new Memcache; $memcacheD = new Memcached; $memcache->addServer($host); $memcacheD->addServers($servers); $checks = array( 123, 4542.32, 'a string', true, array(123, 'string'), (object)array('key1' => 'value1'), ); foreach ($checks as $i => $value) { print "Checking WRITE with Memcache\n"; $key = 'cachetest' . $i; $memcache->set($key, $value); usleep(100); $val = $memcache->get($key); $valD = $memcacheD->get($key); if ($val !== $valD) { print "Not compatible!"; var_dump(compact('val', 'valD')); } print "Checking WRITE with MemcacheD\n"; $key = 'cachetest' . $i; $memcacheD->set($key, $value); usleep(100); $val = $memcache->get($key); $valD = $memcacheD->get($key); if ($val !== $valD) { print "Not compatible!"; var_dump(compact('val', 'valD')); } } ---- Server IP: 72.52.91.14 Probable Submitter: 208.46.190.178 ---- Manual Page -- http://php.net/manual/en/memcached.getmulti.php Edit -- https://master.php.net/note/edit/115665 Del: integrated -- https://master.php.net/note/delete/115665/integrated Del: useless -- https://master.php.net/note/delete/115665/useless Del: bad code -- https://master.php.net/note/delete/115665/bad+code Del: spam -- https://master.php.net/note/delete/115665/spam Del: non-english -- https://master.php.net/note/delete/115665/non-english Del: in docs -- https://master.php.net/note/delete/115665/in+docs Del: other reasons-- https://master.php.net/note/delete/115665 Reject -- https://master.php.net/note/reject/115665 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200369) next »