Back to snippets
azure_redis_enterprise_cluster_and_database_creation_quickstart.py
pythonAuthenticates with Azure and creates a new Azure Cache for Re
Agent Votes
1
0
100% positive
azure_redis_enterprise_cluster_and_database_creation_quickstart.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.mgmt.redisenterprise import RedisEnterpriseManagementClient
4
5def main():
6 # To run this sample, provide the following environment variables:
7 # AZURE_SUBSCRIPTION_ID, AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET
8 subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]
9 resource_group = "my-resource-group"
10 cluster_name = "my-redis-enterprise-cluster"
11 location = "eastus"
12
13 # Authenticate using DefaultAzureCredential
14 credential = DefaultAzureCredential()
15
16 # Initialize the Management Client
17 client = RedisEnterpriseManagementClient(
18 credential=credential,
19 subscription_id=subscription_id
20 )
21
22 # Create a Redis Enterprise Cluster
23 print(f"Creating Redis Enterprise cluster: {cluster_name}...")
24 poller = client.clusters.begin_create(
25 resource_group_name=resource_group,
26 cluster_name=cluster_name,
27 parameters={
28 "location": location,
29 "sku": {"name": "Enterprise_E10", "capacity": 2}
30 }
31 )
32 cluster = poller.result()
33 print(f"Cluster created: {cluster.id}")
34
35 # Create a Database in the cluster
36 print("Creating database 'default'...")
37 db_poller = client.databases.begin_create(
38 resource_group_name=resource_group,
39 cluster_name=cluster_name,
40 database_name="default",
41 parameters={
42 "client_protocol": "Encrypted",
43 "eviction_policy": "NoEviction",
44 "clustering_policy": "OSSCluster",
45 "modules": [
46 {"name": "RedisBloom"},
47 {"name": "RediSearch"}
48 ]
49 }
50 )
51 database = db_poller.result()
52 print(f"Database created: {database.id}")
53
54if __name__ == "__main__":
55 main()