redis - 如何获得额外的客户端连接 (nestjs-ioredis)
问题描述
我在我的 Nestjs 项目中使用 Redis。因此,我正在使用包svtslv/nestjs-ioredis
我在 Nestjs(和 Typescript)方面还不是很有经验。但我试图弄清楚如何获得第二个客户端连接(到同一个数据库),因为我想与订阅者和发布者一起工作。
使用此 Nest 包时,在 Nestjs 中完成的下一个节点实现类似:
const Redis = require("ioredis");
const redis = new Redis();
const pub = new Redis();
redis.subscribe("news", "music", (err, count) => {
// Now we are subscribed to both the 'news' and 'music' channels.
// `count` represents the number of channels we are currently subscribed to.
pub.publish("news", "Hello world!");
pub.publish("music", "Hello again!");
});
redis.on("message", (channel, message) => {
// Receive message Hello world! from channel news
// Receive message Hello again! from channel music
console.log("Receive message %s from channel %s", message, channel);
});
// There's also an event called 'messageBuffer', which is the same as 'message' except
// it returns buffers instead of strings.
redis.on("messageBuffer", (channel, message) => {
// Both `channel` and `message` are buffers.
});
解决方案
RedisModule.forRoot({}, 'secondConnection')
@InjectRedis('secondConnection') private readonly redis: Redis
(非常感谢这个项目的开发者本人)
推荐阅读
- cassandra - 如何使用连接属性(url 属性)通过 ssl 连接 Cassandra
- python - 使用 Python 将文件夹上传到 Azure Blob
- ajax - 无法用新数据重新加载 dataTable
- deep-learning - 非平方图像作为 YOLOv3 的输入
- sbt - 与涉及 scala.xml.Elem 的 Binding.scala 的类型不匹配
- php - findBy - 在 Symfony 中更新多条记录
- vb.net - 设置 DataGridViewComboBoxColumn ItemHeight
- kubernetes - AWS ALB 入口控制器无法通过 TLS 解析
- python - 等待元素。根据是否出现不同的效果。硒蟒
- user-interface - 斯库里改变屏幕尺寸