Google Cloud Memorystore Memcached Operators¶
The Cloud Memorystore for Memcached is a fully managed Memcached service for Google Cloud. Applications running on Google Cloud can achieve extreme performance by leveraging the highly scalable, available, secure Memcached service without the burden of managing complex Memcached deployments.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'
Detailed information is available for Installation.
Instance¶
Operators uses a Instance
for representing instance.
The object can be presented as a compatible dictionary also.
Here is an example of instance
MEMCACHED_INSTANCE = {"name": "", "node_count": 1, "node_config": {"cpu_count": 1, "memory_size_mb": 1024}}
Create instance¶
Create a instance is performed with the
CloudMemorystoreMemcachedCreateInstanceOperator
operator.
create_memcached_instance = CloudMemorystoreMemcachedCreateInstanceOperator(
task_id="create-instance",
location="europe-north1",
instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
instance=MEMCACHED_INSTANCE,
project_id=GCP_PROJECT_ID,
)
Delete instance¶
Delete an instance is performed with the
CloudMemorystoreMemcachedDeleteInstanceOperator
operator.
delete_memcached_instance = CloudMemorystoreMemcachedDeleteInstanceOperator(
task_id="delete-instance",
location="europe-north1",
instance=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
project_id=GCP_PROJECT_ID,
)
Get instance¶
Get an instance is performed with the
CloudMemorystoreMemcachedGetInstanceOperator
operator.
get_memcached_instance = CloudMemorystoreMemcachedGetInstanceOperator(
task_id="get-instance",
location="europe-north1",
instance=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
project_id=GCP_PROJECT_ID,
)
List instances¶
List instances is performed with the
CloudMemorystoreMemcachedListInstancesOperator
operator.
list_memcached_instances = CloudMemorystoreMemcachedListInstancesOperator(
task_id="list-instances", location="-", project_id=GCP_PROJECT_ID
)
Update instance¶
Updating an instance is performed with the
CloudMemorystoreMemcachedUpdateInstanceOperator
operator.
update_memcached_instance = CloudMemorystoreMemcachedUpdateInstanceOperator(
task_id="update-instance",
location="europe-north1",
instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
project_id=GCP_PROJECT_ID,
update_mask=FieldMask(paths=["node_count"]),
instance={"node_count": 2},
)
Update and apply parameters to an instance¶
To update and apply Memcached parameters to an instance use
CloudMemorystoreMemcachedUpdateParametersOperator
and
CloudMemorystoreMemcachedApplyParametersOperator
operator.
update_memcached_parameters = CloudMemorystoreMemcachedUpdateParametersOperator(
task_id="update-parameters",
location="europe-north1",
instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
project_id=GCP_PROJECT_ID,
update_mask={"paths": ["params"]},
parameters={"params": {"protocol": "ascii", "hash_algorithm": "jenkins"}},
)
apply_memcached_parameters = CloudMemorystoreMemcachedApplyParametersOperator(
task_id="apply-parameters",
location="europe-north1",
instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
project_id=GCP_PROJECT_ID,
node_ids=["node-a-1"],
apply_all=False,
)
# update_parameters >> apply_parameters