1

I have :

var g1 = 0,
client.get('r:'+data[i]+':g1:'+(timestamp), function(err, clicks){
    g1 = clicks;
});

console.log(g1);

but not working, how i can get data outside redis callback function ?

napalias
  • 1,145
  • 1
  • 10
  • 21
  • 2
    If `client.get()` is asynchronous, it's not going to work. Being asynchronous means that it doesn't wait for the task to complete, so `console.log(g1)` will execute before `g1 = clicks`. You'll have to work with `g1` or `clicks` inside the callback. – Jonathan Lonowski Aug 28 '13 at 21:06
  • You might also have a look at "[How to return the response from an AJAX call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call)." It focuses on Ajax and jQuery, but the general issue is the same. And, for some of the library-specific solutions, Node.js has its own equivalents -- such as [Q](https://npmjs.org/package/q) for "Deferreds/Promises." – Jonathan Lonowski Aug 28 '13 at 21:13
  • for my purpose i found another way. I used redis and get i change to mget. Now no need send data outside. – napalias Aug 28 '13 at 21:23

0 Answers0