<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Issue 160 in memcached: problems when save objects into the memcached</title>
        <description> Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 160 by jameshu1984: problems when save objects into the memcached
http://code.google.com/p/memcached/issues/detail?id=160

now i'm working on a project with memcached in php, and now i have a  
problem stuck me for some days

when i tried to save object into the memcached, the value stored in the  
memcached didnt match the thing i put into

suppose now i want to save a object

class Test_Obj {
	
	public $a = 1;
	public $b = 2;
	public $c = 3;
	
	/*
	 */
	public function __sleep(){
		print 'test';
		return array('a', 'b');
	}
	/*
	 */
	public function __unset($name){
		unset($this-&amp;gt;$name);
	}
}

$testObj = new Test_Obj();
$memcached = new Memcached();
$memcachedKey = 'test_obj';
$memcached-&amp;gt;setOption(Mist_Memcached::OPT_SERIALIZER,Memcached::SERIALIZER_PHP);
$memcached-&amp;gt;set($memcachedKey, $testObj, 10);
$data = $memcached-&amp;gt;get($memcachedKey);
var_dump($data);

i think the output should be like:
testobject(Test_Obj)#252 (3) { [&amp;quot;a&amp;quot;]=&amp;gt;  int(2) [&amp;quot;b&amp;quot;]=&amp;gt;  int(2)}

but actually the result is different:
testobject(Test_Obj)#252 (3) { [&amp;quot;a&amp;quot;]=&amp;gt;  int(2) [&amp;quot;b&amp;quot;]=&amp;gt;  int(2) [&amp;quot;c&amp;quot;]=&amp;gt;   
int(3) }


what i couldnt understand is, it does invoke the __sleep function, print  
the 'test' string, but the value stored in the memcached still have the 'c'  
property.


and i tested for the second time.

i added some unset code like:
$testObj = new Test_Obj();
$memcached = new Memcached();
$memcachedKey = 'test_obj';
$memcached-&amp;gt;setOption(Mist_Memcached::OPT_SERIALIZER,Memcached::SERIALIZER_PHP);
unset($testObj-&amp;gt;c);
$memcached-&amp;gt;set($memcachedKey, $testObj, 10);
$data = $memcached-&amp;gt;get($memcachedKey);
var_dump($data);

the output is the same as above.
testobject(Test_Obj)#252 (3) { [&amp;quot;a&amp;quot;]=&amp;gt;  int(2) [&amp;quot;b&amp;quot;]=&amp;gt;  int(2) [&amp;quot;c&amp;quot;]=&amp;gt;   
int(3) }

i cant understand why i unset the property 'c' but still get the the  
memcached value with the property 'c'



is there anyone can help me? honestly thanks</description>
        <link>http://www.serverphorums.com/read.php?9,214594,214594#msg-214594</link>
        <lastBuildDate>Sat, 18 May 2013 14:50:32 +0200</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://www.serverphorums.com/read.php?9,214594,214594#msg-214594</guid>
            <title>Issue 160 in memcached: problems when save objects into the memcached</title>
            <link>http://www.serverphorums.com/read.php?9,214594,214594#msg-214594</link>
            <description><![CDATA[ Status: New<br />
Owner: ----<br />
Labels: Type-Defect Priority-Medium<br />
<br />
New issue 160 by jameshu1984: problems when save objects into the memcached<br />
<a href="http://code.google.com/p/memcached/issues/detail?id=160" target="_blank"  rel="nofollow">http://code.google.com/p/memcached/issues/detail?id=160</a><br />
<br />
now i'm working on a project with memcached in php, and now i have a  <br />
problem stuck me for some days<br />
<br />
when i tried to save object into the memcached, the value stored in the  <br />
memcached didnt match the thing i put into<br />
<br />
suppose now i want to save a object<br />
<br />
class Test_Obj {<br />
	<br />
	public $a = 1;<br />
	public $b = 2;<br />
	public $c = 3;<br />
	<br />
	/*<br />
	 */<br />
	public function __sleep(){<br />
		print 'test';<br />
		return array('a', 'b');<br />
	}<br />
	/*<br />
	 */<br />
	public function __unset($name){<br />
		unset($this-&gt;$name);<br />
	}<br />
}<br />
<br />
$testObj = new Test_Obj();<br />
$memcached = new Memcached();<br />
$memcachedKey = 'test_obj';<br />
$memcached-&gt;setOption(Mist_Memcached::OPT_SERIALIZER,Memcached::SERIALIZER_PHP);<br />
$memcached-&gt;set($memcachedKey, $testObj, 10);<br />
$data = $memcached-&gt;get($memcachedKey);<br />
var_dump($data);<br />
<br />
i think the output should be like:<br />
testobject(Test_Obj)#252 (3) { [&quot;a&quot;]=&gt;  int(2) [&quot;b&quot;]=&gt;  int(2)}<br />
<br />
but actually the result is different:<br />
testobject(Test_Obj)#252 (3) { [&quot;a&quot;]=&gt;  int(2) [&quot;b&quot;]=&gt;  int(2) [&quot;c&quot;]=&gt;   <br />
int(3) }<br />
<br />
<br />
what i couldnt understand is, it does invoke the __sleep function, print  <br />
the 'test' string, but the value stored in the memcached still have the 'c'  <br />
property.<br />
<br />
<br />
and i tested for the second time.<br />
<br />
i added some unset code like:<br />
$testObj = new Test_Obj();<br />
$memcached = new Memcached();<br />
$memcachedKey = 'test_obj';<br />
$memcached-&gt;setOption(Mist_Memcached::OPT_SERIALIZER,Memcached::SERIALIZER_PHP);<br />
unset($testObj-&gt;c);<br />
$memcached-&gt;set($memcachedKey, $testObj, 10);<br />
$data = $memcached-&gt;get($memcachedKey);<br />
var_dump($data);<br />
<br />
the output is the same as above.<br />
testobject(Test_Obj)#252 (3) { [&quot;a&quot;]=&gt;  int(2) [&quot;b&quot;]=&gt;  int(2) [&quot;c&quot;]=&gt;   <br />
int(3) }<br />
<br />
i cant understand why i unset the property 'c' but still get the the  <br />
memcached value with the property 'c'<br />
<br />
<br />
<br />
is there anyone can help me? honestly thanks]]></description>
            <dc:creator>Anonymous User</dc:creator>
            <category>Memcached</category>
            <pubDate>Thu, 14 Oct 2010 12:00:11 +0200</pubDate>
        </item>
    </channel>
</rss>
