Support for Redis services without multiple logical databases

Hi!

I’ve been looking into using Azure Managed Redis with a self-hosted Discourse installation and ran into a compatibility issue that I thought might be worth raising.

Azure Managed Redis only supports logical database 0, whereas Discourse currently uses a separate logical database for Sidekiq.

Looking through the Discourse code, I noticed that sidekiq_redis_config automatically increments the configured Redis database:

config.merge!(db: config[:db].to_i + 1)

This means that even with DISCOURSE_REDIS_DB=0, Sidekiq attempts to connect to database 1, resulting in:

Redis::CommandError: ERR DB index is out of range

I was wondering whether there would be any interest in making the Sidekiq Redis configuration a little more flexible, while retaining the existing behaviour by default.

A couple of possible approaches might be:

  • Configurable Sidekiq Redis database: Introducing an optional setting such as DISCOURSE_SIDEKIQ_REDIS_DB, allowing the database index to be configured rather than automatically incremented.
  • Separate Redis connection for Sidekiq: Allowing Sidekiq to connect to a different Redis instance using database 0. This would preserve isolation between Discourse and Sidekiq without requiring multiple logical databases.

We’re trying to reduce the amount of infrastructure we maintain ourselves, so using managed services for things like Redis is preferable to running and maintaining another VM. This is also becoming more relevant as Microsoft is retiring Azure Cache for Redis in favour of Azure Managed Redis, which doesn’t support multiple logical databases.

I appreciate that this isn’t necessarily the standard Discourse deployment model, and there may be good reasons for the existing configuration. However, I thought the compatibility issue was worth raising as it could affect other self-hosted installations using managed Redis services too.

I’d be interested to hear whether either approach would be appropriate, or if there’s an existing configuration option I’ve overlooked.

I’d also be happy to put together a PR if there’s interest in supporting this!

Thanks!

1 Like

Has anyone got any thoughts on this? I’m happy to get a PR together if this is something other folks would find useful.

They way that they do their hosting they are happy with one redis per server. My solution is to just run multiple redis servers if I have multiple web_only containers behind traefik. You’re the only one asking, even after waiting a week, so no, I don’t think anyone else would find it useful.

Understand that I don’t have any control over that, but having been around for over a decade, I’m pretty sure I’m right. I thought a response that you didn’t want was better than none.

Managed Redis is very expensive, last I looked (which is why you don’t want to have a bunch), but just running a bunch of redis containers is pretty easy and doesn’t use a lot of resources.

This is not about having multiple containers, it’s about Sidekiq having it’s very own database since a year or so. Before that, it lived in the Discourse database with its own namespace, but namespaces were removed in Redis 7 so then Discourse switched to the current way of doing it (following the Sidekiq recommendation)

So before, you could get away with having 1 Redis DB per instance. Now you need two.

4 Likes

Happy to make the sidekiq redis configurable, as long as the existing defaults are maintained. pr-welcome

(If you do make a PR, please share a link to it here)

1 Like

Oh. Golly. I certainly missed that. I don’t have two redises anywhere, and now don’t understand how those sites are still working.

At least I got the conversation started! :person_shrugging:

2 Likes

You don’t have two instances, but you do use two databases in your instance.

Normally you get 16 databases (0-15) per Redis instance, so you don’t even notice.

But Azure managed Redis gives you only 1 (DB #0) so then the issue surfaces.

3 Likes

Aha.

You bet I don’t!

Now I get it.

I’ve managed use redis for a long time while understanding almost nothing about it.

I can’t thank you enough without sounding extremely sarcastic. I hope that one day I can track you down and buy you a beer.

3 Likes

Yup, exactly right! I did go down the rabbit hole of running the official Redis image from Dockerhub to confirm this issue, but this is another thing we’d have to maintain (redis image version bumps, patching, additional storage costs, config) as we want to get away from that :smiley:

1 Like

Getting a PR together, will share it here too. It looks like atleast one other person came across this issue too. Sidekiq redis DB index out of range - Product Support / Self-hosting - Discourse Meta

2 Likes