title: Caching relational data using redis
body: <p>I'm building a small social network (users have posts and posts have comments - very basic), using clustered nodejs server and redis as a distributed cache. 
  <br> My approach to cache users posts is to have a <code>sorted set</code> that contains all the user's posts ids ordered by rate(which should be updated every time someone add a like or comment), and actual objects sorted as <code>hash objects</code>. <br>
  So the get user's posts flow should look like this: <br> 
   1. using <code>zrange</code> to get a range of ids from the <code>sorted set</code>. <br>
   2. using <code>multi/exec</code> and <code>hgetall</code> to fetch all the objects at once.</p>
  
  <p>I have a couple of questions: 
  <br>1. in regards of performance issues, will my approach scale when the cache size getting bigger, or maybe I should use lua or something? <br>
   1. in case if I want to continue with current approach, where I should save the sorted set in case of redis crash, if I use the redis persistence this will affect the overall performance, I thought about using a dedicated redis server for the <code>sets</code> (I searched If it is possible to backup only part of the redis data but didn't found anything about it. </p>
  
  <p>My approach => getTopObjects({userID}, 0, 20) : </p>
  
  <pre><code>self.zrange = function(setID, start, stop, multi)
  {
      return execute(this, "zrange", [setID, start, stop], multi);
  };
  
  self.getObject = function(key, multi)
  {
      return execute(this, "hgetall", key, multi);
  };
  
  self.getObjects = function(keys)
  {
      let multi = thisArg.client.multi();
      let promiseArray = [];
  
      for (var i = 0, len = keys.length; i &lt; len; i++)
      {
          promiseArray.push(this.getObject(keys[i], multi));
      }
      return execute(this, "exec", [], multi).then(function(results)
      {
          //TODO: do something with the result.
          return Promise.all(promiseArray);
      });
  };
  
  self.getTopObjects = function(setID, start, stop)
  {
      //TODO: validate the range 
      let thisArg = this;
      return this.zrevrange(setID, start, stop).then(function(keys)
      {
          return thisArg.getObjects(keys);
      });
  };
  </code></pre>