This page describes how to use cross-region replication by creating and working with secondary clusters.
For a conceptual overview of cross-region replication, see About cross-region replication.
Create a secondary cluster
When you create a secondary cluster, Memorystore for Redis Cluster copies and applies some of the primary cluster settings as secondary cluster settings. For more information, see Cluster settings.
You can create a secondary cluster in Memorystore for Redis Cluster by using the Google Cloud console or the Google Cloud CLI.
Console
In the Google Cloud console, go to the Memorystore for Redis Cluster page.
Click a primary cluster. The primary cluster is the parent of the secondary cluster that you're creating.
In the side panel, click the Secondary clusters tab.
Click Add secondary cluster.
In the Add secondary clusters window, make the following changes:
In the Cluster ID field, enter the ID of the secondary cluster that you're creating. The ID must be 1 to 63 characters and use only lowercase letters, numbers, or hyphens. It must start with a lowercase letter, end with a lowercase letter or number, and be unique in its region.
From the Region menu, select the region where you want the secondary cluster to be located.
In the Zonal availability section, select one of the following options:
If you want all of the shards and replicas of the cluster to be distributed across three zones of the region where Memorystore for Redis Cluster creates the cluster, then select the Multi-zone option.
For example, if the region that you select is
us-central1
, and you select the Multi-zone option, then Memorystore for Redis Cluster distributes the cluster's shards and replicas across theus-central1-a
,us-central1-b
, andus-central1-c
zones. In case of a zonal failure, the nodes in the cluster failover to the replicas.If you want all of the shards and replicas of the cluster to be located in one zone of the region where Memorystore for Redis Cluster creates the cluster, select the Single zone option, and then select the zone from the Zone menu.
By using a single zone, you reduce network costs. However, in case of a zonal failure, failover doesn't occur.
From the Replicas menu, select the number of replicas (per shard) for the cluster. You can have zero, one, or two replicas.
From the Network menu, select a network for the cluster. For more information about networking for Memorystore for Redis Cluster, see Networking overview.
Click Add secondary cluster.
gcloud
To create a secondary cluster, use the gcloud redis clusters create
command.
gcloud redis clusters create CLUSTER_ID \ --project=PROJECT_ID \ --region=REGION_ID \ --cross-cluster-replication-role=secondary \ --network=NETWORK \ --primary-cluster=PRIMARY_CLUSTER_PATH
Make the following replacements:
- CLUSTER_ID: the ID of the secondary cluster that you're creating. The ID must be 1 to 63 characters and use only lowercase letters, numbers, or hyphens. It must start with a lowercase letter, end with a lowercase letter or number, and be unique in its region.
- PROJECT_ID: the ID of the project where you want to create the secondary cluster. This is the same project where the primary cluster is located.
- REGION_ID: the ID of the region where you want the secondary cluster to be located.
- NETWORK: the network used to create the cluster. It must use
this format:
projects/NETWORK_PROJECT_ID/global/networks/NETWORK_ID
. The network ID that you use must match the network ID that the service connection policy uses. Otherwise, you can't create the secondary cluster. - PRIMARY_CLUSTER_PATH: the path of the primary cluster. For
example:
projects/my-project/locations/us-central1/clusters/my-primary-cluster
. You can choose any cluster in your project to be the primary cluster, as long as it's not a secondary cluster.
For example:
gcloud redis clusters create my-secondary-cluster \ --project=my-project \ --region=asia-east1 \ --cross-cluster-replication-role=secondary \ --network=projects/my-project/global/networks/default --primary-cluster=projects/my-project/locations/us-central1/clusters/my-primary-cluster
View a secondary cluster
You can view summary information about a secondary cluster by using the Google Cloud console or the Google Cloud CLI.
Console
In the Google Cloud console, go to the Memorystore for Redis Cluster page.
Click the expander arrow next to a primary cluster. This cluster is the parent of the secondary cluster about which you want to view information.
Click the secondary cluster. Summary information about the cluster appears.
gcloud
To view information about a secondary cluster, including a membership field
that lists the primary and secondary clusters in the replication group, use
the gcloud redis clusters describe
command.
gcloud redis clusters describe CLUSTER_ID \ --region=REGION_ID \
Make the following replacements:
- CLUSTER_ID: the ID of the secondary cluster
- REGION_ID: the ID of the region where the secondary cluster is located
Perform a switchover
A switchover lets you reverse the roles of the primary and secondary clusters by promoting a secondary cluster to a primary cluster for disaster recovery purposes.
You can perform a switchover by using the Google Cloud console or the Google Cloud CLI.
Console
In the Google Cloud console, go to the Memorystore for Redis Cluster page.
Click the expander arrow next to a primary cluster. This cluster is the parent of the secondary cluster that you want to switchover.
Click the secondary cluster.
Click Promote to Primary.
In the Promote secondary cluster to primary? dialog, enter the ID of the secondary cluster, and then click Promote.
After the switchover is complete, you must reconnect your applications to the new primary cluster.
gcloud
To perform a switchover, use the gcloud redis clusters switchover
command.
gcloud redis clusters switchover CLUSTER_ID \ --project=PROJECT_ID \ --region=REGION_ID \
Make the following replacements:
- CLUSTER_ID: the ID of the secondary cluster that you want to switchover
- PROJECT_ID: your project ID
- REGION_ID: the ID of the region where the secondary cluster is located
After the switchover is complete, you must reconnect your applications to the new primary cluster.
Detach secondary clusters
Detaching one or more secondary clusters from their primary cluster makes them fully functional independent clusters that allow both reads and writes. For more information, see How to work with cross-region replication.
You can detach secondary clusters by using the Google Cloud console or the Google Cloud CLI.
Detach a secondary cluster
This section explains how to detach a secondary cluster from its primary cluster.
Console
In the Google Cloud console, go to the Memorystore for Redis Cluster page.
Click a primary cluster. This is the parent of the secondary cluster that you're detaching from the primary cluster.
In the side panel, click the Secondary clusters tab.
Select the checkbox next to the ID of the secondary cluster that you're detaching from the primary cluster.
Click Detach from Primary.
In the Detach secondary cluster? dialog, enter the ID of the secondary cluster, and then click Detach.
gcloud
To detach a secondary cluster, use the gcloud redis clusters detach
command.
gcloud redis clusters detach CLUSTER_ID \ --project=PROJECT_ID \ --region=REGION_ID
Make the following replacements:
- CLUSTER_ID: the ID of the secondary cluster that you want to detach
- PROJECT_ID: your project ID
- REGION_ID: the ID of the region where the secondary cluster is located
Detach multiple secondary clusters
This section explains how to detach multiple secondary clusters from their primary cluster. You can also use the procedure in this section to detach an unavailable secondary cluster from its primary cluster.
Console
In the Google Cloud console, go to the Memorystore for Redis Cluster page.
Click a primary cluster. This is the parent of the secondary clusters that you're detaching from the primary cluster.
In the side panel, click the Secondary clusters tab.
Select the checkboxes next to the IDs of the secondary clusters that you're detaching from the primary cluster.
Click Detach from Primary.
In the Detach secondary clusters? dialog, do the following:
Enter the IDs of the secondary clusters. Use commas to separate the IDs.
Click Detach.
gcloud
To detach multiple secondary clusters, use the gcloud redis clusters detach-secondaries
command.
gcloud redis clusters detach-secondaries PRIMARY_CLUSTER_ID \ --clusters-to-detach=SECONDARY_CLUSTERS \ --project=PROJECT_ID \ --region=PRIMARY_CLUSTER_REGION_ID
Make the following replacements:
- PRIMARY_CLUSTER_ID: the ID of the primary cluster.
- SECONDARY_CLUSTERS: the secondary clusters that you want to
detach. Use commas to separate the cluster IDs. Each secondary cluster must
have this format:
projects/PROJECT_ID/locations/REGION_ID/clusters/CLUSTER_ID
. - PROJECT_ID: your project ID.
- PRIMARY_CLUSTER_REGION: the ID of the region where your primary cluster is located.
For example:
gcloud redis clusters detach-secondaries my-primary-cluster \ --clusters-to-detach=projects/my-project/locations/us-west4/clusters/my-secondary-cluster-1,projects/my-project/locations/asia-southeast2/clusters/my-secondary-cluster-2 \ --project=my-project \ --region=us-central1
Update cluster settings
This section provides links to update cluster settings. The process for updating cluster settings is different, depending on whether you change settings on the primary cluster or secondary cluster. For more information about how to update settings, see Cluster settings.
Update settings on the primary cluster
You must change the following settings on the primary cluster. After you do, Memorystore for Redis Cluster synchronizes the changes to the secondary clusters.
- Scale the cluster's capacity
- Configure the cluster
- Prevent the deletion of the cluster
- Manage persistence for the cluster
Update settings on the secondary cluster
You must change the following settings on the secondary cluster:
- Configure whether the cluster is single-zone or multi-zone
- Scale the cluster's replica count
- Set maintenance windows for the cluster
Delete clusters that use cross-region replication
This section explains how to delete primary and secondary clusters that use cross-region replication.
Delete a primary cluster
To delete a primary cluster, do the following:
- Detach or delete all secondary clusters.
- To delete the primary cluster, follow the instructions at Delete clusters.
To protect against accidental deletion, you can't delete primary and secondary clusters simultaneously.
Delete a secondary cluster
To delete a secondary cluster, follow the instructions at Delete clusters. For the cluster ID, use the ID of the secondary cluster.