gpt4 book ai didi

node.js - Laravel 5 使用 Node 和 Laravel-Echo-Server 将事件广播到 WildCard channel

转载 作者:可可西里 更新时间:2023-11-01 11:12:53 25 4
gpt4 key购买 nike

我有两个角色,医生和病人......

当患者执行操作 A 时,我希望向医生列表广播,而不是所有医生,而是他们的列表..

在我的测试中,我能够通过在 Node 中使用 redis 订阅前缀为 Doctor 和连字符然后是 UserID 的 channel 来实现此目的...

redis.subscribe('Doctor-1', function(err, count) {
});

但是,对于生产,我不能硬编码那个 ID,我需要的是像下面这样的东西

redis.subscribe('Doctor-*', function(err, count) {
});

但是通配符好像不行...

关于如何订阅通配符有什么想法吗?

最佳答案

Redis.io, PubSub Documentation

Wikipedia, Glob Programming

The Redis Pub/Sub implementation supports pattern matching. Clients may subscribe to glob-style patterns in order to receive all the messages sent to channel names matching a given pattern.

For instance:

PSUBSCRIBE news.*

因此您的代码段可以更改为

redis.subscribe('Doctor.*', function(err, count) {});

因此它将收到 ID 为 Doctor.1 的医生的任何信息或更深入

Doctors.<groupId>.<DoctorId>等等。

关于node.js - Laravel 5 使用 Node 和 Laravel-Echo-Server 将事件广播到 WildCard channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47997319/

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