5
votes

Scenario: Two instances of an application share the same redis instance, but use different databases. The application makes use of the redis pub/sub functions to exchange data between services.

Problem: When application instance A publishes something (on redis database 1), application instance B (running on redis database 2) receives the message.

Expectation: As both instances of the application use a different database, I would expect not only that the keys in redis are hold separately, but pub/sub subscribers aswell.

Question: Can I tell redis to keep pub/sub separate for each database?

1

1 Answers

7
votes

No - PubSub is shared across all clients connected to the server, regardless of their currently SELECTed database (shared database/numbered database/keyspace). While you can use different channels and such, real separation is possible only by using two Redis instances.

Note: using shared/numbered databases isn't recommended - always use dedicated Redis instances per app/service/use case