0
0
Azurecloud~5 mins

Azure Cache for Redis - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes your app needs to remember data quickly to work faster. Azure Cache for Redis helps by storing data in a fast place so your app can get it without waiting long.
When your website needs to show user info instantly without waiting for a database.
When you want to keep session data for users so they stay logged in smoothly.
When your app does many repeated calculations and you want to save results to avoid doing them again.
When you want to share data quickly between different parts of your app running on multiple servers.
When you want to reduce the load on your main database by caching frequent queries.
Config File - main.tf
main.tf
provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "East US"
}

resource "azurerm_redis_cache" "example" {
  name                = "example-redis-cache"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  capacity            = 1
  family              = "C"
  sku_name            = "Basic"
  enable_non_ssl_port = false
}

This Terraform file creates an Azure Redis Cache instance.

  • provider: sets Azure as the cloud provider.
  • resource_group: a container for your resources in Azure.
  • redis_cache: the Redis cache instance with basic settings for testing or small apps.
Commands
This command prepares Terraform to work with Azure by downloading necessary plugins.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/azurerm... - Installing hashicorp/azurerm v3.64.0... - Installed hashicorp/azurerm v3.64.0 (signed by HashiCorp) Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work.
This command creates the Redis Cache and resource group in Azure automatically without asking for confirmation.
Terminal
terraform apply -auto-approve
Expected OutputExpected
azurerm_resource_group.example: Creating... azurerm_resource_group.example: Creation complete after 2s [id=/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources] azurerm_redis_cache.example: Creating... azurerm_redis_cache.example: Creation complete after 30s [id=/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.Cache/Redis/example-redis-cache] Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
-auto-approve - Skip manual approval to speed up deployment
This Azure CLI command checks the details of the Redis Cache to confirm it is running.
Terminal
az redis show --name example-redis-cache --resource-group example-resources
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.Cache/Redis/example-redis-cache", "location": "East US", "name": "example-redis-cache", "properties": { "provisioningState": "Succeeded", "hostName": "example-redis-cache.redis.cache.windows.net", "port": 6380, "sslPort": 6380 }, "resourceGroup": "example-resources", "sku": { "name": "Basic", "family": "C", "capacity": 1 }, "type": "Microsoft.Cache/Redis" }
Key Concept

If you remember nothing else from this pattern, remember: Azure Cache for Redis stores data in memory to make your app faster by avoiding slow database calls.

Common Mistakes
Trying to connect to Redis without enabling the correct ports or SSL settings.
The connection will fail because Azure Redis Cache requires SSL by default and blocks non-SSL ports unless enabled.
Use the SSL port (usually 6380) and enable SSL in your client settings to connect securely.
Not creating or specifying the resource group before deploying Redis Cache.
Azure resources must belong to a resource group; deployment will fail without it.
Create a resource group first or include it in your deployment configuration.
Summary
Use Terraform to create an Azure Redis Cache instance with a resource group.
Run 'terraform init' to prepare the environment and 'terraform apply' to deploy the cache.
Verify the cache is running using Azure CLI with 'az redis show'.