title: NodeJS, Redis and MySQL
body: <p>Please has anyone ever used <code>NodeJS</code> + <code>Redis</code> + <code>MySQL</code>
  The goal is to have NodeJS fetch data from Redis and only reach MySQL if data not found, also update <code>MySQL</code> back with the data.</p>
  
  <p>Then how can i run relational request from Redis knowing its a <code>NoSQL</code> <code>in-memory DB</code></p>
  
  <p>I have read that Redis is better than <code>Memcached</code> and it seems to be faster so I wanted to try it out but it seems all tutorial i can lay my hands on are just <code>PHP</code> based.</p>
  
  <p>Currently I use NodeJs + MySQL as below (example) : </p>
  
  <pre><code>var d = new Date();
  var date = d.getFullYear() + '-' + paddnum(Math.round(d.getMonth() + 1)) + '-' + paddnum(d.getDate()) + ' ' + paddnum(d.getHours()) + ':' + paddnum(d.getMinutes()) + ':' + paddnum(d.getSeconds());
  
  var query = `INSERT INTO comments (COMMENT, POSTID)
                          VALUES ('{"author":"` + data.userid + `", "comment": "` + data.comment + `", "time":"` + date + `"}', ` + data.postid + `)
                          ON DUPLICATE KEY UPDATE
                              COMMENT = CONCAT(COMMENT, ',{"author":"` + data.userid + `", "comment": "` + data.comment + `", "time":"` + date + `"}'),
                              POSTID = ` + data.postid;
  //console.log(query);
  connection.query(query,
      function(err, results) {
          if (err) {
              return err;
          }
          return results;
      }
  );
  </code></pre>