How to Temporarily Disable Azure Redis Cache Without Deleting It


3 views

When working with Azure Redis Cache during development or testing phases, you might want to temporarily disable it to save costs and resources without losing your configuration. Unlike some Azure services, Redis Cache doesn't have a simple "disable" button in the portal.

Azure provides several approaches to control your Redis Cache instance:

  • Scaling down to the lowest tier (Basic C0)
  • Using PowerShell/Azure CLI to stop the service
  • Implementing firewall rules to block access

The most practical approach is to scale your cache down to the smallest possible size when not in use:


# PowerShell example to scale down Redis Cache
$resourceGroupName = "YourResourceGroup"
$cacheName = "YourRedisCache"
Set-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -Size "C0"

For those preferring Azure CLI, here's how to achieve the same:


# Azure CLI command to scale Redis Cache
az redis update --name YourRedisCache --resource-group YourResourceGroup --sku Basic --vm-size C0

If you need to completely block access while maintaining the instance:


# Add firewall rule to block all IPs
New-AzRedisCacheFirewallRule -Name "BlockAll" -ResourceGroupName "YourResourceGroup" -CacheName "YourRedisCache" -StartIP "0.0.0.0" -EndIP "0.0.0.0"
  • Scaling down may take a few minutes
  • Minimum tier (C0) still incurs minimal costs
  • Connection strings remain the same when scaling back up
  • Data persistence depends on your configuration

For regular developers, consider automating this with Azure Automation:


# Sample runbook to scale down Redis Cache after hours
workflow ScaleDown-RedisCache {
    param(
        [Parameter(Mandatory=$true)]
        [string]$ResourceGroupName,
        [Parameter(Mandatory=$true)]
        [string]$CacheName
    )
    
    # Authenticate to Azure
    $connection = Get-AutomationConnection -Name "AzureRunAsConnection"
    Connect-AzAccount -ServicePrincipal -Tenant $connection.TenantID -ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint
    
    # Scale down the cache
    Set-AzRedisCache -ResourceGroupName $ResourceGroupName -Name $CacheName -Size "C0"
}

When working with Azure Redis Cache in development or testing scenarios, you often need a way to temporarily disable the service without deleting the entire instance. The Azure portal doesn't provide a direct "disable" button, but we have several technical workarounds.

The most cost-effective approach is scaling down to the Basic tier with minimal resources when not in use:

// Azure CLI command to scale down
az redis update --name YourCacheName --resource-group YourRG --sku Basic --vm-size C0

This reduces the cache to the smallest possible size (C0 - 250MB) while maintaining your configuration and connection strings.

For scheduled downtime (like nights/weekends), create a PowerShell script to scale down and back up:

# Scale down
Set-AzRedisCache -Name "YourCache" -ResourceGroupName "YourRG" -Size "C0" -Sku "Basic"

# Scale back up when needed 
Set-AzRedisCache -Name "YourCache" -ResourceGroupName "YourRG" -Size "C1" -Sku "Standard"

If you need to prevent access while keeping the cache running:

// Add restrictive firewall rule via ARM template
{
  "properties": {
    "redisFirewallRules": [{
      "name": "BlockAll",
      "startIP": "0.0.0.0",
      "endIP": "0.0.0.0"
    }]
  }
}

For a hands-off approach, implement an Azure Function triggered by a schedule:

const { DefaultAzureCredential } = require("@azure/identity");
const { RedisManagementClient } = require("@azure/arm-redis");

module.exports = async function (context, myTimer) {
    const client = new RedisManagementClient(new DefaultAzureCredential(), "subscription-id");
    
    // Scale down at 7PM
    if(myTimer.isPastDue) {
        await client.redis.update("resource-group", "cache-name", {
            sku: { name: "Basic", family: "C", capacity: 0 }
        });
    }
    // Scale up at 7AM would be similar
};
  • Basic tier has no SLA - only use for dev/test
  • C0 instances have limited throughput (250MB RAM)
  • Connection strings remain valid during scaling
  • Firewall changes take effect immediately