How to achive this is node Js/Express with Redis ? basically storing a call back value to a variable

My data structure is like below in redis. I want to get all the value in list and it's relavent data from other sets.

Data structure :

lpush mylist test1
lpush mylist test2
lpush mylist test3

set test1 "test1 value1"
set test1 "test1 value2"
set test2 "test2 value1"
set test2 "test2 value2"

I want to get all values from list and relevant set values.

I tried like this below.

var redis        = require('redis')
var redis_client = redis.createClient();


var test = redis_client.lrange(conv_id, 0, -1, function (error, response) {
                     return response;
             });

var datas = redis_client.mget(test, function (error, response) {
                     res.send("datas_text", {data: response});
             });

How to get the callback value ?

But this way it is working.

 redis_client.lrange(conv_id, 0, -1, function (error, response) {
                   redis_client.mget(response, function (err, datas) {
                      res.send("datas_text", {data: datas});
                   });
             });

since this is an async function call return won't work here, you have to restructure your code a little and pass in another callback function if you would like to continue working with the response data.

i've posted a short example to a similar question, have a look here Usage of callback functions and asynchronous requests , hope this helps and you get an idea of the callback coding style.

You have to remember that node.js works asynchronously; what it means is that when your code runs all time consuming activities are being set to run on the background and the variable that is supposed to hold returning value will be null.

What you have to do is create a callback function that will run when the process is finished; read up this free ebook: http://www.nodebeginner.org/ it explains how node.js works very well.

Good luck!