You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Create, query, and delete an Azure Redis cache - Azure CLI
3
-
description: This Azure CLI code sample shows how to create an Azure Managed Redis instance using the command az redisenterprise create. It then gets details of an Azure Managed Redis instance, including provisioning status, the hostname, ports, and keys for an Azure Redis instance. Finally, it deletes the cache.
2
+
title: Create, query, and delete a cache using Azure CLI
3
+
description: Use the Azure CLI to create an Azure Redis instance, get cache details like status, hostname, ports, and keys, and delete the cache.
4
4
5
5
6
6
ms.devlang: azurecli
7
7
ms.topic: sample
8
-
ms.date: 03/11/2022
8
+
ms.date: 05/08/2025
9
9
zone_pivot_groups: redis-type
10
10
ms.custom: devx-track-azurecli, ignite-2024
11
11
appliesto:
12
12
- ✅ Azure Managed Redis
13
13
- ✅ Azure Cache for Redis
14
14
---
15
15
16
-
# Create an Azure Redis cache using the Azure CLI
16
+
# Manage an Azure Redis cache using the Azure CLI
17
17
18
-
In this scenario, you learn how to create an Azure Redis cache instance. You then learn to get details of the cache, including provisioning status, the hostname, ports, and keys for the cache. Finally, you learn to delete the cache.
18
+
This article describes how to create and delete an Azure Redis cache instance by using the Azure CLI. The article also shows how to use the Azure CLI to get cache details including provisioning status, hostname, ports, and keys.
- Make sure you're signed in to Azure with the subscription you want to create your cache under. To use a different subscription than the one you're signed in with, run `az account set -s <subscriptionId>`, replacing `<subscriptionId>` with the subscription ID you want to use.
25
25
26
26
::: zone pivot="azure-managed-redis"
27
27
28
-
## Azure Managed Redis
28
+
>[!NOTE]
29
+
>Azure Managed Redis uses the Azure CLI [az redisenterprise](/cli/azure/redisenterprise) commands. The `redisenterprise` extension for Azure CLI version 2.61.0 or higher prompts you for installation the first time you run an `az redisenterprise` command.
30
+
>
31
+
>Azure Cache for Redis uses the `az redisenterprise` commands for Enterprise tiers and the [az redis](/cli/azure/redis) commands for Basic, Standard, and Premium tiers. You can use the following scripts to create and manage Azure Managed Redis or Azure Cache for Redis Enterprise. For Azure Cache for Redis Basic, Standard, and Premium, use the [Azure Cache for Redis](create-manage-cache.md?pivots=azure-cache-redis) scripts.
This sample is broken. When it is fixed, we can fix this include.
38
+
-->
39
+
To create an Azure Managed Redis cache by using Azure CLI, the `name`, `location`, `resourceGroup`, and `sku` parameters are required. Other parameters are optional and have defaults.
33
40
34
-
::: zone pivot="azure-cache-redis"
41
+
You can use the Azure CLI script in this section to create an Azure Managed Redis cache with default settings. You can also use the following other methods to create a cache:
The cache`name` must be a string of 1-63 characters that's unique in the [Azure region](https://azure.microsoft.com/regions/). The name can contain only numbers, letters, and hyphens, must start and end with a number or letter, and can't contain consecutive hyphens.
39
49
40
-
::: zone-end
50
+
The `location` should be an Azure region near other services that use your cache.
41
51
42
-
::: zone pivot="azure-managed-redis"
52
+
Choose a [sku](https://azure.microsoft.com/pricing/details/cache/) that has the appropriate features and performance for your cache.
Microsoft Entra authentication is enabled by default for all new caches and is recommended for security.
45
55
46
-
### Run the script
56
+
>[!IMPORTANT]
57
+
>Use Microsoft Entra ID with managed identities to authorize requests against your cache if possible. Authorization using Microsoft Entra ID and managed identity provides better security and is easier to use than shared access key authorization. For more information about using managed identities with your cache, see [Use Microsoft Entra for cache authentication with Azure Managed Redis](../entra-for-authentication.md).
This sample is broken. When it is fixed, we can fix this include.
51
-
-->
59
+
Transport Layer Security (TLS) 1.2-1.3 encryption is enabled by default for all new caches. You can enable the non-TLS port and connections during or after cache creation, but for security reasons, disabling TLS isn't recommended.
60
+
61
+
The following script sets variables, and then uses the [az group create](/cli/azure/group) and [az redisenterprise create](/cli/azure/redisenterprise#az-redisenterprise-create) commands to create a resource group with an Azure Managed Redis Balanced B1 SKU cache in it.
The following script uses the [az redisenterprise show](/cli/azure/redisenterprise#az-redisenterprise-show) and [az redisenterprise database list-keys](/cli/azure/redisenterprise/database#az-redisenterprise-database-list-keys) commands to get and display the name, hostname, ports, and keys details for the preceding cache.
70
85
71
-
# Get details of an Azure Managed Redis
86
+
>[!IMPORTANT]
87
+
>The `list-keys` operation works only when access keys are enabled for the cache. The output of this command might compromise security by showing secrets, and may trigger a sensitive information warning. For more information, see [Use Azure CLI to manage sensitive information](https://go.microsoft.com/fwlink/?linkid=2258669).
88
+
89
+
```azurecli
90
+
# Get details of an Azure Managed Redis cache
72
91
echo "Showing details of $cache"
73
92
az redisenterprise show --name "$cache" --resource-group $resourceGroup
74
93
75
94
# Retrieve the hostname and ports for an Azure Redis Cache instance
The following script uses the [az group delete](/cli/azure/group) and [az redisenterprise delete](/cli/azure/redisenterprise#az-redisenterprise-delete) commands to delete the preceding cache, and then delete its resource group.
113
+
114
+
```azurecli
89
115
# Delete a redis cache
90
116
echo "Deleting $cache"
91
117
az redisenterprise delete --name "$cache" --resource-group $resourceGroup -y
92
118
93
119
# echo "Deleting all resources"
94
120
az group delete --resource-group $resourceGroup -y
>Use these scripts to create and manage Azure Cache for Redis Basic, Standard, and Premium tiers with the Azure CLI [az redis](/cli/azure/redis) commands.
129
+
>
130
+
>Azure Cache for Redis Enterprise tiers and Azure Managed Redis use the [az redisenterprise](/cli/azure/redisenterprise) commands. The `redisenterprise` extension for Azure CLI version 2.61.0 or higher prompts you for installation the first time you run an `az redisenterprise` command.
131
+
>
132
+
>To create and manage an Azure Cache for Redis Enterprise-tier cache, use the [Azure Managed Redis](create-manage-cache.md?pivots=azure-managed-redis) scripts.
105
133
106
-
## Sample reference
134
+
## Create an Azure Cache for Redis cache
107
135
108
-
This script uses the following commands to create a resource group and an Azure Managed Redis. Each command in the table links to command specific documentation.
136
+
You can use the following Azure CLI script to create an Azure Cache for Redis Basic, Standard, or Premium-tier cache. To create and manage an Azure Cache for Redis Enterprise-tier cache, use the [Azure Managed Redis](create-manage-cache.md?pivots=azure-managed-redis) scripts.
109
137
110
-
| Command | Notes |
111
-
|---|---|
112
-
|[az group create](/cli/azure/group)| Creates a resource group in which all resources are stored. |
To create an Azure Cache for Redis Basic, Standard, or Premium cache by using Azure CLI, the `name`, `location`, `resourceGroup`, `sku`, and `size` parameters are required. Other parameters are optional and have defaults.
117
139
118
-
::: zone-end
140
+
You can use the Azure CLI script in this section to create an Azure Cache for Redis Basic cache with default settings. You can also use the following other methods to create a cache:
119
141
120
-
::: zone pivot="azure-cache-redis"
142
+
-[Azure portal (Basic, Standard, or Premium)](../../azure-cache-for-redis/quickstart-create-redis.md)
The cache `name` must be a string of 1-63 characters that's unique in the [Azure region](https://azure.microsoft.com/regions/). The name can contain only numbers, letters, and hyphens, must start and end with a number or letter, and can't contain consecutive hyphens.
123
149
124
-
### Run the script
150
+
The `location` should be an Azure region near other services that use your cache.
This sample is broken. When it is fixed, we can fix this include.
129
-
-->
152
+
Choose a [sku](https://azure.microsoft.com/pricing/details/cache/) and `size` that have the appropriate features and performance for your cache.
153
+
154
+
Transport Layer Security (TLS) 1.2-1.3 encryption is enabled by default for all new caches. You can enable the non-TLS port and connections during or after cache creation, but for security reasons, disabling TLS isn't recommended.
155
+
156
+
>[!IMPORTANT]
157
+
>Microsoft Entra authentication is recommended for security. You can enable Microsoft Entra Authentication during or after cache creation.
158
+
>
159
+
>Use Microsoft Entra ID with managed identities to authorize requests against your cache if possible. Authorization using Microsoft Entra ID and managed identity provides better security and is easier to use than shared access key authorization. For more information about using managed identities with your cache, see [Use Microsoft Entra ID for cache authentication](../../azure-cache-for-redis/cache-azure-active-directory-for-authentication.md).
160
+
161
+
The following script uses the [az group create](/cli/azure/group) and [az redis create](/cli/azure/redis#az-redis-create) commands to create a resource group with an Azure Cache for Redis Basic C0 cache in it.
The following script uses the [az redis show](/cli/azure/redis#az-redis-show) and [az redis list-keys](/cli/azure/redis#az-redis-list-keys) commands to get and display the name, hostname, ports, and keys details for the preceding cache.
186
+
187
+
>[!IMPORTANT]
188
+
>The `list-keys` operation works only when access keys are enabled for the cache. The output of this command might compromise security by showing secrets, and may trigger a sensitive information warning. For more information, see [Use Azure CLI to manage sensitive information](https://go.microsoft.com/fwlink/?linkid=2258669).
189
+
190
+
```azurecli
191
+
192
+
# Get details of an Azure Cache for Redis cache
151
193
echo "Showing details of $cache"
152
194
az redis show --name "$cache" --resource-group $resourceGroup
153
195
154
-
# Retrieve the hostname and ports for an Azure Redis Cache instance
196
+
# Retrieve the hostname and ports for an Azure Redis instance
The following script uses the [az group delete](/cli/azure/group) and [az redis delete](/cli/azure/redis#az-redis-delete) commands to delete the preceding cache, and then delete its resource group.
180
214
181
215
```azurecli
182
-
az group delete --resource-group $resourceGroup
183
-
```
184
-
185
-
## Sample reference
186
-
187
-
This script uses the following commands to create a resource group and an Azure Cache for Redis. Each command in the table links to command specific documentation.
216
+
# Delete an Azure Redis cache
217
+
echo "Deleting $cache"
218
+
az redis delete --name "$cache" --resource-group $resourceGroup -y
188
219
189
-
| Command | Notes |
190
-
|---|---|
191
-
|[az group create](/cli/azure/group)| Creates a resource group in which all resources are stored. |
az group delete --resource-group $resourceGroup -y
222
+
```
196
223
197
224
::: zone-end
198
225
199
-
## Next steps
200
-
201
-
For more information on the Azure CLI, see [Azure CLI documentation](/cli/azure).
226
+
## Related content
202
227
203
-
For an Azure Managed Redis CLI script sample that creates a Azure Managed Redis with clustering, see [Azure Managed Redis with Clustering](../../azure-cache-for-redis/scripts/create-manage-premium-cache-cluster.md)
228
+
-[Azure CLI documentation](/cli/azure)
229
+
-[Create a Premium Azure Cache for Redis with clustering](../../azure-cache-for-redis/scripts/create-manage-premium-cache-cluster.md)
0 commit comments