How to use the command 'az redis' (with examples)
This article provides examples of how to use the ‘az redis’ command, which is used to manage Redis caches in Azure. The command allows users to create, update, export, and delete Redis caches.
Use case 1: Create a new Redis cache instance
Code:
az redis create --location location --name name --resource-group resource_group --sku Basic|Premium|Standard --vm-size c0|c1|c2|c3|c4|c5|c6|p1|p2|p3|p4|p5
Motivation: Creating a new Redis cache instance allows users to deploy and configure an in-memory data store that can be used to improve application performance and scalability. It can be useful when developing applications that require high-performance data storage and retrieval.
Explanation:
--location
: The Azure region where the Redis cache will be created.--name
: The name of the Redis cache instance.--resource-group
: The resource group in which the Redis cache will be created.--sku
: The pricing tier or SKU of the Redis cache. It can be Basic, Premium, or Standard.--vm-size
: The size or configuration of the Redis cache virtual machine. It can be c0, c1, c2, c3, c4, c5, c6, p1, p2, p3, p4, or p5.
Example output:
{
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{redisCacheName}",
"location": "East US",
"name": "{redisCacheName}",
"properties": {
"enableNonSslPort": false,
"redisConfiguration": {
"maxclients": "2000"
},
...
},
...
}
Use case 2: Update a Redis cache
Code:
az redis update --name name --resource-group resource_group --sku Basic|Premium|Standard --vm-size c0|c1|c2|c3|c4|c5|c6|p1|p2|p3|p4|p5
Motivation: Updating a Redis cache allows users to modify its configuration and scalability to meet the changing needs of an application.
Explanation:
--name
: The name of the Redis cache instance.--resource-group
: The resource group where the Redis cache is located.--sku
: The new pricing tier or SKU of the Redis cache.--vm-size
: The new size or configuration of the Redis cache virtual machine.
Example output:
{
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{redisCacheName}",
"location": "East US",
"name": "{redisCacheName}",
"properties": {
"enableNonSslPort": false,
"redisConfiguration": {
"maxclients": "3000"
},
...
},
...
}
Use case 3: Export data stored in a Redis cache
Code:
az redis export --container container --file-format file-format --name name --prefix prefix --resource-group resource_group
Motivation: Exporting data from a Redis cache allows users to create backups or migrate the data to another system for analysis or storage purposes.
Explanation:
--container
: The name of the blob storage container where the exported data will be stored.--file-format
: The format of the exported data file. It can be either “rdb” or “redis”.--name
: The name of the Redis cache instance.--prefix
: The prefix string to use when generating the name of the exported data file.--resource-group
: The resource group where the Redis cache is located.
Example output:
Exporting Redis cache data to container 'backup-container' in file format 'rdb'.
Export completed successfully.
Use case 4: Delete a Redis cache
Code:
az redis delete --name name --resource-group resource_group --yes
Motivation: Deleting a Redis cache allows users to remove a Redis cache instance that is no longer needed, reducing resource consumption and costs.
Explanation:
--name
: The name of the Redis cache instance to be deleted.--resource-group
: The resource group where the Redis cache is located.--yes
: A confirmation flag indicating that the user wants to proceed with the deletion.
Example output:
Deleting Redis cache '{redisCacheName}'...
Deleted Redis cache '{redisCacheName}' successfully.
Conclusion:
The ‘az redis’ command is a powerful tool for managing Redis caches in Azure. By using this command, users can create, update, export, and delete Redis cache instances, allowing for efficient and scalable data storage and retrieval in their applications.