0

I'm using StackExchangeRedis in Asp.Net core 3.1 app via microsoft.extensions.caching.stackexchangeredis nuget v3.1 package. I'm on standard tier pricing plan of Azure Cache for Redis. As per the docs by default there are 16 databases and the default DB is 0. I want to try experimenting with DB numbers in my code. This is how I setup in Startup.cs file:

services.AddStackExchangeRedisCache(options =>
            {
                options.InstanceName = Configuration.GetValue<string>("RedisCache:InstanceName");
                options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions
                {
                    
                    AbortOnConnectFail = false,
                    AllowAdmin = false,
                    Ssl = true,
                    ConnectRetry = 3,
                    ReconnectRetryPolicy = new LinearRetry(1500),
                    ConnectTimeout = 5000,
                    SyncTimeout = 5000,
                    DefaultDatabase = 1,
                    EndPoints = {
                        { 
                            Configuration.GetValue<string>("RedisCache:Server"), 
                            Configuration.GetValue<int>("RedisCache:Port")
                        },
                    },
                    Password = Configuration.GetValue<string>("RedisCache:Password"),
                    
                };
            });

I see there is an option to customize the database number to use via DefaultDatabase option. I have seen this article here but still couldn't understand the usage much.

Do I need to think about database id or is this something azure/redis handles internally for performance reasons and its abstracted from me? If this is something I need to worry about while developing my applications? I'm planning to leverage this cache as shared instance for my apps (50-100).

Sam
  • 519
  • 1
  • 7
  • 32

1 Answers1

1

You may want to worry about this at production scale but, for development, it's not necessary and even inadvisable.

See What's the Point of Multiple Redis Databases?

sirdank
  • 3,351
  • 3
  • 25
  • 58
  • So after reading the link, my understanding: *"Multiple databases has become a deprecated feature, so not recommended in production. It has been deprecated because it is, in general, better to launch multiple Redis servers on the same machine rather than using multiple databases. Redis is single threaded. Thus, a single Redis server with multiple databases only uses one CPU core. On the other hand, if multiple Redis servers are used, it is possible to take advantage of multiple CPU cores. Multiple databases make administration of Redis harder and may complicate performance and resource."* – Sam Oct 09 '20 at 16:58