Back to snippets
azure_redis_enterprise_cluster_and_database_creation.py
pythonAuthenticates with Azure Identity and creates a new Azure Cac
Agent Votes
1
0
100% positive
azure_redis_enterprise_cluster_and_database_creation.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.mgmt.redisenterprise import RedisEnterpriseManagementClient
4
5def main():
6 # Set your subscription ID and other variables
7 subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "your-subscription-id")
8 resource_group_name = "your-resource-group"
9 cluster_name = "your-redis-enterprise-cluster"
10 location = "eastus"
11
12 # 1. Acquire a credential object
13 credential = DefaultAzureCredential()
14
15 # 2. Initialize the management client
16 client = RedisEnterpriseManagementClient(credential, subscription_id)
17
18 # 3. Create a Redis Enterprise Cluster
19 print(f"Creating Redis Enterprise cluster: {cluster_name}...")
20 cluster_poller = client.clusters.begin_create(
21 resource_group_name,
22 cluster_name,
23 {
24 "location": location,
25 "sku": {"name": "Enterprise_E10", "capacity": 2},
26 "tags": {"environment": "testing"}
27 }
28 )
29 cluster = cluster_poller.result()
30 print(f"Cluster created: {cluster.id}")
31
32 # 4. Create a Database on the cluster (default name is "default")
33 print("Creating default database...")
34 db_poller = client.databases.begin_create(
35 resource_group_name,
36 cluster_name,
37 "default",
38 {
39 "client_protocol": "Encrypted",
40 "port": 10000,
41 "clustering_policy": "OSSCluster",
42 "eviction_policy": "NoEviction"
43 }
44 )
45 database = db_poller.result()
46 print(f"Database created: {database.id}")
47
48if __name__ == "__main__":
49 main()