node js memcached client

106 views
Skip to first unread message

nit...@cloudion.net

unread,
Oct 7, 2015, 10:46:40 AM10/7/15
to nodejs
I am using memcached node js client. I am not getting the JSON output when performing the get operation on it. Here is my code

memcached.get(id, function( err, result ){
  if( err ) console.error( err );
  console.log( result );
});
and the output is 

a:2:{s:7:"passkey";s:40:"8c779538d8c4ed54cf8a89d1e59518557febf0ac";s:7:"userkey";s:7:"5b9ce84";}
How to get the userkey from this output or how to get the output as json?

Aria Stewart

unread,
Oct 7, 2015, 10:54:29 AM10/7/15
to nodejs
The short answer: put JSON in to memcache if that's what you want to get back out.

Now looking at this, this is PHP Serialization format, using a PHP array (used as an object -- string keys) -- which means it's the same data that JSON can represent, represented as PHP Serialization instead. If you want to store JSON, you'll have to use PHP's json functions to get a string, and store that.

I suspect you're being bit by the special assumptions PHP's memcache driver does, where it serializes things you put in in some (or all) cases. PHP memcache drivers are remarkably full of magic for such a simple protocol.

You could also use a node decoder for PHP's format -- with simple objects that should be straightforward -- and just not use JSON.

Good luck! 

Aria
Reply all
Reply to author
Forward
0 new messages