# Create a Memorystore for Memcached instance by using the gcloud CLI

This quickstart walks you through the steps to create a Memorystore for Memcached
instance, connect to the instance, send some Memcached commands, and delete the
instance.

> [!CAUTION]
> **Caution:** You cannot create a Memorystore for Memcached instance without first having a private services access connection established. See [Networking](https://docs.cloud.google.com/memorystore/docs/memcached/networking.md.txt) for details on the private services access connection that is required for Memorystore for Memcached.

## Before you begin

1. If you haven't already, [install the Google Cloud SDK](https://docs.cloud.google.com/sdk/docs.md.txt).

   When prompted, choose the project that you selected or created above.
2. If you already have the Google Cloud SDK installed, update it.

   ```
   gcloud components update
   ```
3. Enable the Service Networking API for your project.   
   [Enable the Service Networking API](https://console.cloud.google.com/apis/library/servicenetworking.googleapis.com)
4. Enable the Memorystore for Memcached API for your project.   
   [Enable the Memorystore for Memcached API](https://console.cloud.google.com/apis/api/memcache.googleapis.com)

<br />

## Creating a Memorystore for Memcached instance

To create a Memorystore for Memcached instance:

1. Open a terminal window.

2. Set the project you'd like to create your instance in as the default project
   in `gcloud` by entering the following command:

   ```
   gcloud config set core/project project-id
   ```
3. Enter the following command to create a Memcached instance with 3 nodes (each
   node with 4 cores and 10GB memory) in the us-central1 region:

   ```
   gcloud memcache instances create myinstance --node-count=3 --node-cpu=4 \
       --node-memory=10GB --region=us-central1 --memcached-version=1.6.15
   ```
4. After you create the instance, run the following `describe` command, and
   write down the IP address of one of your nodes.

   ```
   gcloud memcache instances describe myinstance --region=us-central1
   ```

## Connecting to your instance from a Compute Engine VM

> [!NOTE]
> **Note:** The connecting client must be located in the same region as the Memcached instance. Also, in order to connect the client must use the same network as the Memcached instance, or it must use a Shared VPC network.

1. Connect to a Linux VM. For steps to connect to a Linux VM, see [Quickstart Using a Linux VM](https://docs.cloud.google.com/compute/docs/create-linux-vm-instance.md.txt).
   If you used a Debian based image to create your VM instance as described in
   the quickstart, install `telnet` using `apt-get`:

   ```
   sudo apt-get install telnet
   ```
2. From the terminal, telnet to the IP address of one of the Memcached nodes,
   replacing <var translate="no">variables</var> with appropriate values.

   ```
   telnet node-ip-address 11211
   ```

   If it works correctly, you should see the following output with the
   `[bracketed-variables]` replaced by your project's variables:

   ```
   Trying [node-ip-address]…
   Connected to [node-ip-address]
   ```
3. In the telnet session, enter some Memcached commands:

   Enter:

   ```
   get greeting
   ```

   Result:

   ```
   END
   ```

   Enter:

   ```
   set greeting 1 0 11
   hello world
   ```

   Result:

   ```
   STORED
   ```

   Enter:

   ```
   get greeting
   ```

   Result:

   ```
   VALUE greeting 1 11
   hello world
   END
   ```

Memorystore for Memcached supports standard open source Memcached libraries.

## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, follow these steps.

1. To avoid incurring charges to your Google Cloud account for the
   resources used in this quickstart, delete the instance by entering the
   following command:

   ```
   gcloud memcache instances delete myinstance --region=us-central1
   ```

   Enter `Y` to confirm the instance deletion:

   ```
   You are about to delete instance [myinstance] in [us-central1].
   Any associated data will be lost.
   Do you want to continue (Y/n)? Y
   Delete request issued for: [myinstance]
   ```
2. If successful, `gcloud` returns the following response:

   ```
   Deleted instance [myinstance]
   ```

## What's next

- [Connect to a Memcached instance](https://docs.cloud.google.com/memorystore/docs/memcached/connecting-memcached-instance).

- [Use the Auto Discovery service](https://docs.cloud.google.com/memorystore/docs/memcached/using-auto-discovery).

- [Monitor your Memcached instance](https://docs.cloud.google.com/memorystore/docs/memcached/monitoring-instances).