This page lists the gcloud CLI commands needed to set up prerequisites, provision an instance in a service project, describe an instance, and delete an instance. In order to accomplish these tasks you should follow the instructions in each section of this page.
For more detailed guidance for these tasks, see the following pages:
Enable APIs
Enable the following APIs needed for configuring a service connection policy, configuring Shared VPC, and creating a Memorystore for Valkey instance.
gcloud
Enable the following APIs in the service project:
gcloud services enable --project=SERVICE_PROJECT_ID networkconnectivity.googleapis.com gcloud services enable --project=SERVICE_PROJECT_ID serviceconsumermanagement.googleapis.com gcloud services enable --project=SERVICE_PROJECT_ID memorystore.googleapis.com
Replace the SERVICE_PROJECT_ID with your service project ID.
Enable the following APIs in the host project:
gcloud services enable --project=HOST_PROJECT_ID networkconnectivity.googleapis.com
Replace the HOST_PROJECT_ID with the ID of your host project.
Create a service connection policy
Next, a service connection policy must be created for the host project of the Shared VPC where the policy is defined, network, region, and the subnet(s) where you want to provision the Memorystore for Valkey instance. Usually this is done by your Network Admin, or you might have the necessary permission run the command if you have the Required role.
This quickstart uses the default
network and default
subnet. IP addresses
for your instance are allocated on this default subnet in the region.
gcloud
To create the service connection policy, run the
create
command:gcloud network-connectivity service-connection-policies create POLICY_NAME \ --network=default \ --project=HOST_PROJECT_ID \ --region=REGION \ --service-class=gcp-memorystore \ --subnets=https://www.googleapis.com/compute/v1/projects/HOST_PROJECT_ID/regions/REGION/subnetworks/default
Replace the following:
- POLICY_NAME is your desired policy name.
- HOST_PROJECT_ID is the host project ID.
- REGION is the same region where you want to provision your Memorystore for Valkey instance.
To validate if the policy was created successfully, run the
list
command:gcloud network-connectivity service-connection-policies list \ --region=REGION \ --project=HOST_PROJECT_ID
Replace the following:
- HOST_PROJECT_ID is the host project ID.
- REGION is the region where the service connection policy is defined.
Create an instance
To create an instance in the service project attached to the Shared VPC, run the following command:
gcloud
gcloud beta memorystore instances create INSTANCE \ --project=SERVICE_PROJECT_ID \ --location=REGION \ --node-type=NODE_TYPE \ --shard-count=SHARD_COUNT \ --replica-count=REPLICA_COUNT \ --psc-auto-connections=network=projects/HOST_PROJECT_ID/global/networks/default,projectId=SERVICE_PROJECT_ID
Replace the following:
- INSTANCE is the instance ID.
- SERVICE_PROJECT_ID is the service project ID.
REGION is the region where you want to provision your instance.
NODE_TYPE is your chosen node type. Accepted values are:
shared-core-nano
standard-small
highmem-medium
highmem-xlarge
For more details on node types and instance configurations, see Instance and node specification.
SHARD_COUNT determines the number of shards in your instance. Shard count determines the total memory capacity for storing instance data. To see more details about instance specification, see Instance and node specification.
REPLICA_COUNT is your desired number of read replicas (per shard). Accepted values are
0
,1
, and2
.HOST_PROJECT_ID is the host project ID.
Describe the instance
To view instance details, run the following command:
gcloud
gcloud beta memorystore instances describe INSTANCE \ --project=SERVICE_PROJECT_ID \ --location=REGION
Replace the following:
- INSTANCE is the instance ID.
- SERVICE_PROJECT_ID is the service project ID.
- REGION is the region where your instance is located.
Delete the instance
To delete an instance, run the following command:
gcloud
gcloud beta memorystore instances delete INSTANCE \ --project=SERVICE_PROJECT_ID \ --location=REGION
Replace the following:
- INSTANCE is the instance ID.
- SERVICE_PROJECT_ID is the service project ID.
- REGION is the region where your instance is located.