Welcome! Log In Create A New Profile

Advanced

Issue 160 in memcached: problems when save objects into the memcached

Posted by Anonymous User 
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->$name);
}
}

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

i think the output should be like:
testobject(Test_Obj)#252 (3) { ["a"]=> int(2) ["b"]=> int(2)}

but actually the result is different:
testobject(Test_Obj)#252 (3) { ["a"]=> int(2) ["b"]=> int(2) ["c"]=>
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->setOption(Mist_Memcached::OPT_SERIALIZER,Memcached::SERIALIZER_PHP);
unset($testObj->c);
$memcached->set($memcachedKey, $testObj, 10);
$data = $memcached->get($memcachedKey);
var_dump($data);

the output is the same as above.
testobject(Test_Obj)#252 (3) { ["a"]=> int(2) ["b"]=> int(2) ["c"]=>
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
Sorry, only registered users may post in this forum.

Click here to login