如何使用 python 创建 Gcp 内存存储

我正在尝试自动创建 gcp 内存存储,但没有找到使用 python 创建它的方法。请帮忙。



尚方宝剑之说
浏览 114回答 2
2回答

繁花如伊

您可以使用Python Client for Google Cloud Memorystore for Redis API来创建它。您可以使用Python客户端库的create_instance方法,该方法根据指定的层和内存大小创建Redis实例async create_instance(request: google.cloud.redis_v1.types.cloud_redis.CreateInstanceRequest = None, *, parent: str = None, instance_id: str = None, instance: google.cloud.redis_v1.types.cloud_redis.Instance = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ()) 

Smart猫小萌

&nbsp; &nbsp; from google.cloud import redis_v1beta1&nbsp; &nbsp; from google.cloud.redis_v1beta1 import enums&nbsp; &nbsp; client = redis_v1beta1.CloudRedisClient()&nbsp; &nbsp; parent = client.location_path('<project>', '<location>')&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; instance_id = 'test-instancee'&nbsp; &nbsp; tier = enums.Instance.Tier.BASIC&nbsp; &nbsp; memory_size_gb = 1&nbsp; &nbsp; instance = {'tier': tier, 'memory_size_gb': memory_size_gb}&nbsp; &nbsp; response = client.create_instance(parent, instance_id, instance)&nbsp; &nbsp; def callback(operation_future):&nbsp; &nbsp; &nbsp; &nbsp; # Handle result.&nbsp; &nbsp; &nbsp; &nbsp; result = operation_future.result()&nbsp; &nbsp; response.add_done_callback(callback)&nbsp; &nbsp; # Handle metadata.&nbsp; &nbsp; # metadata = response.metadata()&nbsp; &nbsp; print "Created"这段代码可以正常工作,但是对于 python2,有没有办法在 python3 中使用它,请提及。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python