1
votes

I want to connect to a specific database in our new Azure Redis cache but can't seem to figure out how to do it.

I've tried adding the database id to connection string in various forms as well as looking for GetDatabase(dbid) on the IDistributedcache object (which doesn't seem to exist).

FYI, I want to use the same cache for our testing and production without having to pay for an additional redis cache so I'm open to alternative approaches.

1
I've seen the same cache used for non-prod and production before and it can potentially be a huge pain point. Be sure to consider the risk of accidentally having data cross between the two while you're determining how your keys are going to work. - Kyle Burns
And this is why I really wanted to separate them using different databases in the redis cache. - Ben Thomson
So I think the best way to do this is to use a ConnectionMultiplexer as a singleton service (which means you can use a config object and also means a lot less time creating connections to Redis too). I'll experiment and add my answer later for anyone else that runs in to this as it took me a while to figure out this was the best approach. - Ben Thomson

1 Answers

1
votes

You could also use the ConnectionMultiplexer object directly and access the Database via the GetDatabase method.