Events
31 Mar, 23 - 2 Apr, 23
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In this article, you learn how to create an Azure Resource Manager template that deploys an Azure Web App with Azure Cache for Redis. You'll learn the following deployment details:
You can use this template for your own deployments, or customize it to meet your requirements.
For more information about creating templates, see Authoring Azure Resource Manager templates. To learn about the JSON syntax and properties for cache resource types, see Microsoft.Cache resource types.
For the complete template, see Web App with Azure Cache for Redis template.
In this template, you deploy:
To run the deployment automatically, select the following button:
With Azure Resource Manager, you define parameters for values you want to specify when the template is deployed. The template includes a section called Parameters that contains all of the parameter values. You should define a parameter for those values that vary based on the project you're deploying or the environment you're deploying to. Do not define parameters for values that are constant. Each parameter value is used in the template to define the resources that are deployed.
When defining parameters, use the allowedValues field to specify which values a user can provide during deployment. Use the defaultValue field to assign a value to the parameter, if no value is provided during deployment.
We will describe each parameter in the template.
The name of the web app that you wish to create.
"siteName":{
"type":"string"
}
The name of the App Service plan to use for hosting the web app.
"hostingPlanName":{
"type":"string"
}
The pricing tier for the hosting plan.
"sku": {
"type": "string",
"allowedValues": [
"F1",
"D1",
"B1",
"B2",
"B3",
"S1",
"S2",
"S3",
"P1",
"P2",
"P3",
"P4"
],
"defaultValue": "S1",
"metadata": {
"description": "The pricing tier for the hosting plan."
}
}
The template defines the values that are permitted for this parameter, and assigns a default value of S1
if no value is specified.
The instance size of the hosting plan (small, medium, or large).
"workerSize":{
"type":"string",
"allowedValues":[
"0",
"1",
"2"
],
"defaultValue":"0"
}
The template defines the values that are permitted for this parameter (0
, 1
, or 2
), and assigns a default value of 0
if no value is specified. The values correspond to small, medium, and large.
The pricing tier of the new Azure Cache for Redis.
"cacheSKUName": {
"type": "string",
"allowedValues": [
"Basic",
"Standard",
"Premium"
],
"defaultValue": "Basic",
"metadata": {
"description": "The pricing tier of the new Azure Cache for Redis."
}
},
The template defines the values that are permitted for this parameter (Basic, Standard, or Premium), and assigns a default value (Basic) if no value is specified. Basic provides a single node with multiple sizes available up to 53 GB. Standard provides two-node Primary/Replica with multiple sizes available up to 53 GB and 99.9% SLA.
The family for the sku.
"cacheSKUFamily": {
"type": "string",
"allowedValue/s": [
"C",
"P"
],
"defaultValue": "C",
"metadata": {
"description": "The family for the sku."
}
},
The size of the new Azure Cache for Redis instance.
For the Basic and Standard families:
"cacheSKUCapacity": {
"type": "int",
"allowedValues": [
0,
1,
2,
3,
4,
5,
6
],
"defaultValue": 0,
"metadata": {
"description": "The size of the new Azure Cache for Redis instance. "
}
}
The Premium value cache capacity is defined the same, except the allowed values run from 1 to 5 instead of from 0 to 6.
The template defines the integer values that are permitted for this parameter (0 through 6 for the Basic and Standard families; 1 through 5 for the Premium family). If no value is specified, the template assigns a default value of 0 for Basic and Standard, 1 for Premium.
The values correspond to following cache sizes:
Value | Basic and Standard cache size |
Premium cache size |
---|---|---|
0 | 250 MB (default) | n/a |
1 | 1 GB | 6 GB (default) |
2 | 2.5 GB | 13 GB |
3 | 6 GB | 26 GB |
4 | 13 GB | 53 GB |
5 | 26 GB | 120 GB |
6 | 53 GB | n/a |
This template uses variables to construct names for the resources. It uses the uniqueString function to construct a value based on the resource group ID.
"variables": {
"hostingPlanName": "[concat('hostingplan', uniqueString(resourceGroup().id))]",
"webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]",
"cacheName": "[concat('cache', uniqueString(resourceGroup().id))]"
},
Creates the service plan for hosting the web app. You provide the name of the plan through the hostingPlanName parameter. The location of the plan is the same location used for the resource group. The pricing tier and worker size are specified in the sku and workerSize parameters.
{
"apiVersion": "2015-08-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"sku": {
"name": "[parameters('sku')]",
"capacity": "[parameters('workerSize')]"
},
"properties": {
"name": "[parameters('hostingPlanName')]"
}
},
Creates the Azure Cache for Redis that is used with the web app. The name of the cache is specified in the cacheName variable.
The template creates the cache in the same location as the resource group.
{
"name": "[variables('cacheName')]",
"type": "Microsoft.Cache/Redis",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [ ],
"tags": {
"displayName": "cache"
},
"properties": {
"sku": {
"name": "[parameters('cacheSKUName')]",
"family": "[parameters('cacheSKUFamily')]",
"capacity": "[parameters('cacheSKUCapacity')]"
}
}
}
Creates the web app with name specified in the webSiteName variable.
Notice that the web app is configured with app setting properties that enable it to work with the Azure Cache for Redis. These app settings are dynamically created based on values provided during deployment.
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
],
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]": "empty",
"displayName": "Website"
},
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "appsettings",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('webSiteName'))]",
"[concat('Microsoft.Cache/Redis/', variables('cacheName'))]"
],
"properties": {
"CacheConnection": "[concat(variables('cacheHostName'),'.redis.cache.windows.net,abortConnect=false,ssl=true,password=', listKeys(resourceId('Microsoft.Cache/Redis', variables('cacheName')), '2015-08-01').primaryKey)]"
}
}
]
}
For RedisEnterprise, because the resource types are slightly different, the way to do listKeys is different:
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
],
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]": "empty",
"displayName": "Website"
},
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"type": "config",
"name": "appsettings",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('webSiteName'))]",
"[concat('Microsoft.Cache/RedisEnterprise/databases/', variables('cacheName'), "/default")]",
],
"properties": {
"CacheConnection": "[concat(variables('cacheHostName'),abortConnect=false,ssl=true,password=', listKeys(resourceId('Microsoft.Cache/RedisEnterprise', variables('cacheName'), 'default'), '2020-03-01').primaryKey)]"
}
}
]
}
To deploy the resources to Azure, you must be signed in to your Azure account and you must use the Azure Resource Manager module. To learn about using Azure Resource Manager with either Azure PowerShell or Azure CLI, see:
The following examples assume you already have a resource group in your account with the specified name.
New-AzResourceGroupDeployment -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/web-app-with-redis-cache/azuredeploy.json -ResourceGroupName ExampleDeployGroup
azure group deployment create --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/web-app-with-redis-cache/azuredeploy.json -g ExampleDeployGroup
Events
31 Mar, 23 - 2 Apr, 23
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Deploy Azure infrastructure by using JSON ARM templates - Training
Write JSON Azure Resource Manager templates by using Visual Studio Code to deploy your infrastructure to Azure consistently and reliably.
Certification
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.
Documentation
Provision Web App that uses Azure Cache for Redis using Bicep - Azure Cache for Redis
Use Bicep to deploy web app with Azure Cache for Redis.
Deploy Azure Cache for Redis using Bicep - Azure Cache for Redis
Learn how to use Bicep to deploy an Azure Cache for Redis resource.
What is Azure Cache for Redis? - Azure Cache for Redis
Learn about Azure Cache for Redis to enable cache-aside, content caching, user session caching, job and message queuing, and distributed transactions.