title: Wait for Redis get to set array in Node.JS
body: <p>I'm learning Javascript / Node.JS and it's going well but I ran in some trouble with the code below. When I open the page that emits a hit it outputs the trck_visitors array in Node.JS however. On the first hit this array is empty, it does not show the <strong>trck_visitors[socket.id]</strong> which I just set. If I refresh the page I see in the console.log output the ID from the previous hit but not from the current hit.</p>
  
  <p>Why doesn't it output the <strong>trck_visitors[socket.id]</strong> which I just set but does output the <strong>trck_visitors[socket.id]</strong> from previous hits?</p>
  
  <pre><code>var trck_visitors = [];
  
  io.sockets.on('connection', function (socket) {
      socket.on('hit', function (data) {
              redis.get("Node-&gt;Username-&gt;"+parseInt(getToken), function(err, reply) {
                  if(reply === null){
                      trck_visitors[socket.id] = {'Gebruikersnaam' : 'Gast', 'Page' : data.url};
                  }else{
                      trck_visitors[socket.id] = {'Gebruikersnaam' : reply, 'Page' : data.url};
                  }
              });
  
          console.log(trck_visitors);
      });
  });
  </code></pre>
  
  <h2>Edit:</h2>
  
  <p>Updated the code to the actual code. Redis seems to be the problem, console.log does not wait for redis.get to set <strong>trck_visitors[socket.id]</strong>. How can I make the rest of the code wait for redis.get to set <strong>trck_visitors[socket.id]</strong>?</p>
  
  <p>Thanks in advance</p>