title: For loop in redis with nodejs asynchronous requests
body: <p>I've got a problem with redis and nodejs. I have to loop through a list of phone numbers, and check if this number is present in my redis database. Here is my code : </p>
  
  <pre><code>function getContactList(contacts, callback) {
    var contactList = {};
  
    for(var i = 0; i &lt; contacts.length; i++) {
      var phoneNumber = contacts[i];
  
      if(utils.isValidNumber(phoneNumber)) {
  
        db.client().get(phoneNumber).then(function(reply) {
          console.log("before");
          contactList[phoneNumber] = reply;
        });
      }
    }
  
    console.log("after");
    callback(contactList);
  
  };
  </code></pre>
  
  <p>The "after" console log appears before the "before" console log, and the callback always return an empty <code>contactList</code>. This is because requests to redis are asynchronous if I understood well. But the thing is I don't know how to make it works. 
  How can I do ?</p>