Rails 和 ActionCable。多个环境一台redis服务器

Rails and ActionCable. Several environments with one redis server

我有一堆应用程序:my.coma.my.comb.my.com、..

他们都用一台redis服务器,不同的数据库url: redis://localhost:6379/1, url: redis://localhost:6379/2, ..

但是广播消息会发送到每个应用程序。那是因为 https://redis.io/topics/pubsub:

Pub/Sub has no relation to the key space. It was made to not interfere with it on any level, including database numbers. Publishing on db 10, will be heard by a subscriber on db 1. If you need scoping of some kind, prefix the channels with the name of the environment

Rails 存储库 https://github.com/rails/rails/issues/27224 中存在同样的问题。

我只看到几个选项:

  1. 为每个应用程序使用单独的 redis 服务器
  2. #subscribed 中的前缀 steam_fromstream_from("#{some_config.or_env.channel_prefix}_#{user.id}")
  3. 使用其他提供程序(不是 Redis)

我错过了什么吗?有更好更简单的解决方案吗?

哦,我错过了关于 channel_prefix 的部分。当我们迁移到 5.1 时,我们将使用此功能。