Azure Redis Cache Management

14.5.0 · active · verified Thu Apr 09

The azure-mgmt-redis client library provides functionality to manage Azure Redis Cache instances, including creation, update, deletion, and scaling. It is part of the Azure SDK for Python, currently at version 14.5.0, and follows a continuous release cadence for bug fixes and new features, with major versions introducing breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure, create a `RedisManagementClient`, and then list all Azure Redis Cache instances within a given subscription. Ensure you have set `AZURE_SUBSCRIPTION_ID` and other Azure authentication environment variables (e.g., for service principal) or are logged in via Azure CLI/VS Code.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.redis import RedisManagementClient

# Set your Azure Subscription ID as an environment variable (e.g., AZURE_SUBSCRIPTION_ID)
# Or replace os.environ.get with your actual subscription ID.
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')

# Authenticate using DefaultAzureCredential
# This will try to authenticate using various methods, e.g., environment variables, managed identity, Azure CLI, Visual Studio Code.
credential = DefaultAzureCredential()

# Create a RedisManagementClient
redis_client = RedisManagementClient(credential, subscription_id)

print(f"Listing Redis Caches in subscription {subscription_id}:")

# List all Redis Caches in the subscription
# Operations like .list_by_subscription() return an iterator for paginated results.
try:
    for cache in redis_client.redis.list_by_subscription():
        print(f"  - Name: {cache.name}, Location: {cache.location}, SKU: {cache.sku.name}")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →