php-redis - Is there a way to store PHP object in Redis without serializing it? -
php-redis - Is there a way to store PHP object in Redis without serializing it? -
i trying store user' request url key , php object corresponding key value in redis. tried following:
$redisclient = new redis(); $redisclient->connect('localhost', 6379); $redisclient->set($_server['request_uri'], $this->page); $redistest = $redisclient->get($_server['request_uri']); var_dump($redistest);
however, code value of url key beingness stored in redis type of string
value equal 'object' instead of actual php object. there way store php object without serializing it?
as can see in redis info types, redis supports these 5 info types:
stirng list set hash sorted setso, there no object data-type , therefor not able store object straight value. have serialize first (or json-encode json_encode
function example).
is there problem serializing insist on storing objects directly?
update: according said in comments, can utilize approach indicated in answer
so can use:
$xml = $simplexmlelem->asxml();
before serialization, , after unserialize()
, utilize next code:
$simplexmlelem = simplexml_load_string($xml);
in way, don't have serialize php built-in object simplexmlelement
straight , there no problems.
php redis phpredis
Comments
Post a Comment