Get database info from Azure Cache for Redis

837 views Asked by At

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).

1

There are 1 answers

1
sirdank On

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?