Google Cloud Memorystore Memcached 运算符

适用于 Memcached 的 Cloud Memorystore 是 Google Cloud 的全托管 Memcached 服务。在 Google Cloud 上运行的应用程序可以通过利用高度可扩展、可用、安全的 Memcached 服务实现极高性能,而无需承担管理复杂 Memcached 部署的负担。

先决条件任务

要使用这些运算符,您必须执行以下操作

实例

运算符使用 Instance 来表示实例。该对象也可以表示为兼容字典。

以下是一个实例示例

tests/system/providers/google/cloud/cloud_memorystore/example_cloud_memorystore_memcached.py[源代码]

MEMCACHED_INSTANCE = {
    "name": "",
    "node_count": 1,
    "node_config": {"cpu_count": 1, "memory_size_mb": 1024},
    "zones": [LOCATION + "-a"],
}

创建实例

使用 CloudMemorystoreMemcachedCreateInstanceOperator 运算符执行创建实例。

tests/system/providers/google/cloud/cloud_memorystore/example_cloud_memorystore_memcached.py[源代码]

create_memcached_instance = CloudMemorystoreMemcachedCreateInstanceOperator(
    task_id="create-instance",
    location=LOCATION,
    instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
    instance=MEMCACHED_INSTANCE,
    project_id=PROJECT_ID,
)

删除实例

使用 CloudMemorystoreMemcachedDeleteInstanceOperator 运算符执行删除实例。

tests/system/providers/google/cloud/cloud_memorystore/example_cloud_memorystore_memcached.py[源代码]

delete_memcached_instance = CloudMemorystoreMemcachedDeleteInstanceOperator(
    task_id="delete-instance",
    location=LOCATION,
    instance=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
    project_id=PROJECT_ID,
)

获取实例

使用 CloudMemorystoreMemcachedGetInstanceOperator 运算符执行获取实例。

tests/system/providers/google/cloud/cloud_memorystore/example_cloud_memorystore_memcached.py[源代码]

get_memcached_instance = CloudMemorystoreMemcachedGetInstanceOperator(
    task_id="get-instance",
    location=LOCATION,
    instance=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
    project_id=PROJECT_ID,
)

列出实例

使用 CloudMemorystoreMemcachedListInstancesOperator 运算符执行列出实例。

tests/system/providers/google/cloud/cloud_memorystore/example_cloud_memorystore_memcached.py[源代码]

list_memcached_instances = CloudMemorystoreMemcachedListInstancesOperator(
    task_id="list-instances", location="-", project_id=PROJECT_ID
)

更新实例

使用 CloudMemorystoreMemcachedUpdateInstanceOperator 运算符执行更新实例。

tests/system/providers/google/cloud/cloud_memorystore/example_cloud_memorystore_memcached.py[源代码]

update_memcached_instance = CloudMemorystoreMemcachedUpdateInstanceOperator(
    task_id="update-instance",
    location=LOCATION,
    instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
    project_id=PROJECT_ID,
    update_mask=FieldMask(paths=["node_count"]),
    instance={"node_count": 2},  # 2
)

更新并应用参数到实例

要更新和应用 Memcached 参数到实例,请使用 CloudMemorystoreMemcachedUpdateParametersOperatorCloudMemorystoreMemcachedApplyParametersOperator 运算符。

tests/system/providers/google/cloud/cloud_memorystore/example_cloud_memorystore_memcached.py[源代码]

update_memcached_parameters = CloudMemorystoreMemcachedUpdateParametersOperator(
    task_id="update-parameters",
    location=LOCATION,
    instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
    project_id=PROJECT_ID,
    update_mask={"paths": ["params"]},
    parameters={"params": {"protocol": "ascii", "hash_algorithm": "jenkins"}},
)

apply_memcached_parameters = CloudMemorystoreMemcachedApplyParametersOperator(
    task_id="apply-parameters",
    location=LOCATION,
    instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
    project_id=PROJECT_ID,
    node_ids=["node-a-1"],
    apply_all=False,
)

参考

有关详细信息,请查看

此条目有帮助吗?