0

Please has anyone ever used NodeJS + Redis + MySQL The goal is to have NodeJS fetch data from Redis and only reach MySQL if data not found, also update MySQL back with the data.

Then how can i run relational request from Redis knowing its a NoSQL in-memory DB

I have read that Redis is better than Memcached 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 PHP based.

Currently I use NodeJs + MySQL as below (example) :

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;
    }
);

1 Answer 1

1

Im not sure what you really need, but based on question you need code and module that will work between nodejs code and MySQL db. You can use this module for redis operation git://github.com/NodeRedis/node_redis.git

Now all what you need is connect to redis, fill the data in and then on user request check redis->if found return data if not do db queries. Or vice versa.

Hope this helps.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks seems to be the way forward and its very okay, but what i am confused about now is if i want to do relational query (MULTIPLE JOINS) with redis, thanks again
Well...As far as i know redis doent have JOIN's functionality. It just basically pub/sub system. So it just stores values inside and give it back. But from my experience it's very good to hold some large objects with data and get it back. For example you can save MySQL result to redis and later just get this result from redis multiple times. That approach can save a lot of time. Hope this helps.
thanks alot, after mutiple digging i realize for data requiring RELATIONS all i have to do i create VIEW in MYSQL and save its data in REDIS so the data in request from REDIS will just be VIEWS which goes without relationship

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.