Airflow Summit 2021 is coming July 8-16. Register now!

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:

Instance

Operators uses a Instance for representing instance. The object can be presented as a compatible dictionary also.

Here is an example of instance

airflow/providers/google/cloud/example_dags/example_cloud_memorystore.pyView Source

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.

airflow/providers/google/cloud/example_dags/example_cloud_memorystore.pyView Source

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.

airflow/providers/google/cloud/example_dags/example_cloud_memorystore.pyView Source

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.

airflow/providers/google/cloud/example_dags/example_cloud_memorystore.pyView Source

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.

airflow/providers/google/cloud/example_dags/example_cloud_memorystore.pyView Source

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.

airflow/providers/google/cloud/example_dags/example_cloud_memorystore.pyView Source

update_memcached_instance = CloudMemorystoreMemcachedUpdateInstanceOperator(
    task_id="update-instance",
    location="europe-north1",
    instance_id=MEMORYSTORE_MEMCACHED_INSTANCE_NAME,
    project_id=GCP_PROJECT_ID,
    update_mask=cloud_memcache.field_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.

airflow/providers/google/cloud/example_dags/example_cloud_memorystore.pyView Source

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

Was this entry helpful?