Jdesk / memcached

Automatically exported from code.google.com/p/memcached
0 stars 0 forks source link

problems when save objects into the memcached #160

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by jameshu1...@gmail.com on 14 Oct 2010 at 9:56

GoogleCodeExporter commented 9 years ago
Please use the mailing list or IRC for support requests...

Original comment by dorma...@rydia.net on 15 Apr 2011 at 6:41