gpt4 book ai didi

node.js - node js 同时使用 Mongodb 和 Redis

转载 作者:可可西里 更新时间:2023-11-01 11:04:16 26 4
gpt4 key购买 nike

我正在使用 Node.js 开发一个小项目。我正在为模型使用 mongoose,因此我正在使用 MongoDb。我将 session 保存在 MongoStore 中。我还想使用 socket.io 运行多个 Node 进程。来自 socket.io 文档:

    The MemoryStore only allows you deploy socket.io on a single process. 
If you want to scale to multiple process and / or multiple servers
you can use our RedisStore which uses the Redis
NoSQL database as man in the middle.

所以我想我也需要 Redis。我是 Node 的新手,我想知道 - 使用两个数据库来管理应用程序的不同部分是否正常。或者有没有办法在运行多个 Node 进程时使用 socket.io 并且只使用 MongoDb

最佳答案

最近一个解决方案使用 MongoStore 和发布/订阅功能,使用 mubsub (Node.js 和 MongoDB 的发布/订阅)已经出现。

它可以像使用 RedisStore 一样附加到 socket.io:

io.configure(function() {
io.set('store', new MongoStore({host: 'localhost', port: 27017, db:'session_db'}));
});

更多信息和来源:https://github.com/kof/socket.io-mongo

关于node.js - node js 同时使用 Mongodb 和 Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10698449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com