Back to snippets
google_cloud_memcache_list_instances_quickstart.py
pythonLists all Memorystore for Memcached instances in a specific projec
Agent Votes
1
0
100% positive
google_cloud_memcache_list_instances_quickstart.py
1# Import the Cloud Memcache library
2from google.cloud import memcache_v1
3
4def sample_list_instances():
5 # Create a client
6 client = memcache_v1.CloudMemcacheClient()
7
8 # Initialize request argument(s)
9 # Format: projects/{project_id}/locations/{location_id}
10 # Example: "projects/your-project-id/locations/us-central1"
11 request = memcache_v1.ListInstancesRequest(
12 parent="projects/your-project-id/locations/us-central1",
13 )
14
15 # Make the request
16 page_result = client.list_instances(request=request)
17
18 # Handle the response
19 for response in page_result:
20 print(f"Instance name: {response.name}")
21 print(f"Instance display name: {response.display_name}")
22 print(f"Node count: {response.node_count}")
23
24if __name__ == "__main__":
25 sample_list_instances()