Base solution for your next web application
Open Closed

Azure Managed Redis #12643


User avatar
0
ricardo created

Hello,

Microsoft is signaling the replacement of Azure Cache for Redis with Azure Managed Redis. Is there anything to consider in ASP.NET Zero for this migration?

https://learn.microsoft.com/pt-br/azure/redis/migrate/migrate-basic-standard-premium-understand

thanks.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @ricardo

    Thank you for reaching out. The short answer is that migrating to Azure Managed Redis is very straightforward, and there is nothing to worry about from a framework perspective.

    ASP.NET Zero comes with Redis pre wired but disabled by default. Here is how the architecture handles it:

    • The Abp.RedisCache NuGet package is referenced in Web.Core.csproj.
    • AbpRedisCacheModule is registered as a module dependency in AbpZeroTemplateWebCoreModule.cs.
    • The UseRedis() activation call is commented out, meaning in-memory caching is used by default.
    • Most importantly, all caching in the framework goes through ABP's ICacheManager abstraction, not through direct StackExchange.Redis calls.

    This means there is zero coupling to any specific Redis server version, protocol, or feature.

    What to Consider When Migrating

    Based on the differences with Azure Managed Redis, here is how it impacts an ASP.NET Zero application:

    | Concern | Impact | Details | | :--- | :--- | :--- | | Connection string format | Config change only | Azure Managed Redis uses a different DNS suffix (<region>.redis.azure.net) and port (10000 instead of 6380/6379). Update your appsettings.json accordingly. | | TLS | Config change only | Azure Managed Redis supports only one mode (TLS or non-TLS) at creation time. Add ssl=True to your connection string. | | Single database limitation | No impact | ASP.NET Zero uses DatabaseId: -1 (the default database). No multiple database usage exists out of the box. | | Clustering (enabled by default) | Low risk | Abp.RedisCache uses StackExchange.Redis internally, which fully supports cluster-aware connections. For small caches (<25 GB), you can also use the Nonclustered mode. | | Keyspace notifications (not available)| No impact | ASP.NET Zero does not use keyspace notifications. | | Redis modules | No impact | ASP.NET Zero does not use RediSearch, RedisJSON, or any specific Redis modules. | | VNet injection (not supported)| Check your deployment | If you currently use VNet injection for network isolation, you will need to switch to Azure Private Link. | | Entra ID RBAC (not supported yet)| Check your deployment | If you are using Entra ID RBAC for Redis access, please note this isn't available yet on Azure Managed Redis. |

    Migration Steps for ASP.NET Zero

    If Redis is already enabled in your production environment, the migration involves only configuration changes:

    1. Update connection strings in appsettings.json (and any environment-specific overrides):
      "ConnectionString": "your-cache.eastus.redis.azure.net:10000,password=YOUR_KEY,ssl=True,abortConnect=False"
      
    2. Update Docker Compose variables if using containerized deployments (e.g., in docker-compose-host.yml, docker-compose-mvc.yml).
    3. Choose the right SKU: Azure Managed Redis reserves ~20% of memory for overhead. If your current cache is a C3 (13 GB), look for an AMR SKU with at least 13 GB of usable memory. The "Balanced" tier is a safe starting point.
    4. No code changes are required the ICacheManager abstraction handles the rest automatically.

    ASP.NET Zero's architecture makes this migration seamless. The ABP caching abstraction layer means the framework has no dependency on Redis-specific features, clustering modes, database selection, or protocol details. The migration is purely a configuration-level change update your connection strings, ensure TLS is enabled, and you are good to go.

    If you need any assistance after applying these changes, please do not hesitate to contact us.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    rickfrankel created

    If you want to use Entra ID RBAC it is possible.

    We simply replaced the IAbpRedisCacheDatabaseProvider with our own implementation.

    //Taken from here https://github.com/aspnetboilerplate/aspnetboilerplate/blob/292754bf5368757da2e987b9876a057c4fbffb56/src/Abp.RedisCache/Runtime/Caching/Redis/AbpRedisCacheDatabaseProvider.cs#L10 //But adapted to support azure default credentials connecting. public class ProjectNameAbpRedisCacheDatabaseProvider : IAbpRedisCacheDatabaseProvider, ISingletonDependency { private readonly AbpRedisCacheOptions _options; private readonly Lazy<ConnectionMultiplexer> _connectionMultiplexer;

    /// &lt;summary&gt;
    /// Initializes a new instance of the &lt;see cref=&quot;AbpRedisCacheDatabaseProvider&quot;/&gt; class.
    /// &lt;/summary&gt;
    public ProjectNameAbpRedisCacheDatabaseProvider(AbpRedisCacheOptions options)
    {
        _options = options;
        _connectionMultiplexer = new Lazy&lt;ConnectionMultiplexer&gt;(CreateConnectionMultiplexer);
    }
    
    /// &lt;summary&gt;
    /// Gets the database connection.
    /// &lt;/summary&gt;
    public IDatabase GetDatabase()
    {
        return _connectionMultiplexer.Value.GetDatabase(_options.DatabaseId);
    }
    
    private ConnectionMultiplexer CreateConnectionMultiplexer()
    {
        var configurationOptions = ConfigurationOptions.Parse(_options.ConnectionString).ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()).WaitAndUnwrapException();
        return ConnectionMultiplexer.Connect(configurationOptions);
    }
    

    }

    Then in your Module add the following

                Configuration.ReplaceService&lt;IAbpRedisCacheDatabaseProvider, ProjectNameAbpRedisCacheDatabaseProvider&gt;(DependencyLifeStyle.Singleton);
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @rickfrankel

    Thank you for sharing this.

    Yes, that approach makes sense. Since ASP.NET Zero uses IAbpRedisCacheDatabaseProvider as the abstraction point, replacing it with a custom implementation is a valid way to enable Entra ID RBAC authentication for Redis.

    Your example is especially helpful because it shows that the existing AbpRedisCacheDatabaseProvider can be adapted with DefaultAzureCredential and ConfigureForAzureWithTokenCredentialAsync(...) without requiring broader changes in the caching layer.

    We appreciate you sharing the implementation details here. This should be useful for others who want to use Azure Managed Redis with Entra ID RBAC in ASP.NET Zero.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)