douyang2530 2016-08-01 06:50
浏览 214
已采纳

NodeJS,Redis和MySQL

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条回答 默认 最新

  • doukui4836 2016-08-01 10:17
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法