Reputation: 1613
I use redis
(predis/predis composer) to save some id in php like this:
$redis = new Client();
$mailJson = $redis->get('mail');
$mail = json_decode($mailJson);
$no = rand(100,500);
array_push($mail, $no);
$redis->set('mail', json_encode($mail));
and i retrieve this array like this:
var redis = require("redis"),
client = redis.createClient();
client.on('connect', function() {
client.get('mail', function(err, mailIds) {
console.log(mailIds);
});
});
But mailIds
variable is string and not an array like this:
[1,200,500,500,400,100,200,100]
Is way can access mailIds
items ?
Upvotes: 1
Views: 161
Reputation: 91734
You need to parse the json (a string) so that you get an array in javascript / node.js:
client.get('mail', function(err, mailIds) {
// parse the json
mailIdsArray = JSON.parse(mailIds);
console.log(mailIdsArray);
});
Upvotes: 3