How to set redis DB ID in Docker container?

AI-generated summary

Users are discussing how to set a Redis DB ID in a Docker container for multiple Discourse instances. TomekB wants to pass a DB ID to a web-only container so that multiple forums use their own cache. rluba has a similar issue and found the corresponding setting redis_db in discourse_defaults.conf, which can be set as DISCOURSE_REDIS_DB in the container YAML.

However, sam warns that using a different Redis database ID for multiple Discourse instances can cause major breakage, as the Message Bus relies on pub/sub, which is always on “db 0” and not configurable. ryanerwin asks if this warning is still accurate, and sam confirms that it is, citing Redis documentation that pub/sub is tied to DB 0 and has no relation to the key space or database numbers.

I have one data container and I would like to use several web_only containers (several forums on separate servers). How to I pass a DB ID to web_only container so that multiple forums use their own cache?

Without this the stats reported in Admin → Reports are mixed up between different forums.

I’ve got the same issue. I have an existing redis cluster (with replication and failover) that I want Discourse to use, but I can’t find a way to tell Discourse which database index to use.

I’ve found the corresponding setting via this answer. It’s hidden in discourse_defaults.conf:

It’s called redis_db, so the corresponding setting in the container yaml should be DISCOURSE_REDIS_DB.

Definitely do not do anything like this :fire: . Message Bus which is responsible for long polling relies on pub/sub, pub/sub is always on “db 0” not configurable.

If you try to co-host multiple Discourses on one Redis DB expect some very major amount of breakage.

Thank you for the warning! :bowing_man:

@sam 님, 2018년에 메시지 버스가 Redis db 0에만 전용으로 연결된다는 :fire: 경고는 여전히 유효한가요, 아니면 이제 다른 Redis 인스턴스의 데이터베이스 ID를 사용하여 서로 다른 Discourse 인스턴스를 호스팅할 수 있게 되었나요?

multisite-configuration-with-docker howto에서 db_id: 2가 정의되어 있는 것을 확인했는데, 이것이 Redis 데이터베이스 ID를 가리키는 것이라 생각하여 이렇게 질문해 봅니다 :face_with_monocle:

         secondsite:
           adapter: postgresql
           database: b_discourse
           pool: 25
           timeout: 5000
           db_id: 2
           host_names:
             - b.discourse.example.com

네, 제 생각에는 여전히 100% 맞습니다. Redis의 PUB/SUB는 DB 0에 묶여 있습니다. Discourse 멀티사이트는 여러 인스턴스가 db 0을 사용하는 단일 Redis와 함께 원활하게 작동하도록 설계되었습니다.

Pub/Sub는 키 공간(key space)과 관련이 없습니다. 데이터베이스 번호를 포함하여 어떤 수준에서도 키 공간에 간섭하지 않도록 만들어졌습니다.

db 10에서 게시하면 db 1의 구독자도 이를 수신합니다.