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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!