I am new to Redis and Node.JS and have been attempting to use the two together. However I am a little confused by which functions I can use one after the other.
The following code appears to run synchronously, with the database growing in size:
client.dbsize(function(err, numKeys) {
console.log("DB Size before hashes added" + numKeys);
return numKeys;
});
for (var i = 0; i < 100; i++) {
client.hmset(i, "username", "username", "answer", "answer");
client.zadd('answer', i, i);
};
client.dbsize(function(err, numKeys) {
console.log("DB Size after hashes added" + numKeys);
return numKeys;
});
However, when I then try to query the sorted set 'answer' to return an array, this array, 'reply' is not immediately available to other redis functions outside the callback to 'zrevrangebyscore'.
client.zrevrangebyscore('answer', 100, 0, function(err, reply) {
console.log (reply);
return reply;
});
For example, a subsequent 'hgetall' function called on reply[1] returns undefined. Should I use all Redis functions (including the hmset and dbsize) in an asynchronous manner with callbacks/client.multi etc. or do some work effectively if used synchronously? All help gratefully received.