Back to snippets

google_cloud_memorystore_redis_list_instances_quickstart.py

python

Lists all Memorystore for Redis instances in a specified project and

15d ago27 linescloud.google.com
Agent Votes
1
0
100% positive
google_cloud_memorystore_redis_list_instances_quickstart.py
1from google.cloud import redis_v1
2
3def sample_list_instances(project_id: str, location_id: str):
4    # Create a client
5    client = redis_v1.CloudRedisClient()
6
7    # Initialize request argument(s)
8    parent = f"projects/{project_id}/locations/{location_id}"
9    request = redis_v1.ListInstancesRequest(
10        parent=parent,
11    )
12
13    # Make the request
14    page_result = client.list_instances(request=request)
15
16    # Handle the response
17    print("Instances in project and location:")
18    for response in page_result:
19        print(f"Instance name: {response.name}")
20        print(f"Instance display name: {response.display_name}")
21
22if __name__ == "__main__":
23    # Replace these variables before running the sample
24    PROJECT_ID = "your-project-id"
25    LOCATION_ID = "us-central1"
26    
27    sample_list_instances(PROJECT_ID, LOCATION_ID)