How to run script flush all Azure Redis

291 Views Asked by At

I tried to set up the end task after deploying the Web App to clean the cache in Azure Redis to avoid making old caches effective. I tried both command az cli, and Powershell both of them did the same restart, but all data in the Redis cache still did not flush, even in activilogs showing data will be lost after restart. I have tested on both Tier C0 and P1 Redis. Has anyone given me a script to flush all Azure Redis? I am setting only SSL port 3380.

This is the command I run:

-CLI

az redis force-reboot --name $Redis --resource-group $ResourceGroup --reboot-type AllNodes

-Powershell:

Reset-AzRedisCache -ResourceGroupName $ResourceGroup -Name $Redis -RebootType "AllNodes" -Force

-activities Log: enter image description here

Check in redis tool manager still have data: enter image description here

Thank you for helping me!

setup task Flushall Azure Redis

1

There are 1 best solutions below

0
Sampath On

The command force-reboot used for Reboot specified Redis node from this MSDOC

az redis force-reboot --reboot-type {AllNodes, PrimaryNode, SecondaryNode}
                      [--ids]
                      [--name]
                      [--resource-group]
                      [--shard-id]
                      [--subscription]
  • Login to Azure using az login.

  • To create a Azure Redis Cache

    New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "North Central US"
  • For Clearing/flush Azure Redis Cache using PowerShell.
Invoke-Command -ScriptBlock { redis-cli -h <hostname>.redis.cache.windows.net -p <redisPort> -a <password> }

Invoke-Command -ScriptBlock { redis-cli flushall }

Output:

enter image description here

enter image description here

  • Easy way is to go to overview, click on console and execute a flushall command:

enter image description here

Another method:

$redisServer.FlushAllDatabases() # Dispose connection 

$redis_cache.Dispose() Write-Host "Cache flush done" -ForegroundColor Yellow