Quickstart using the gcloud command-line tool

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.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  6. If you haven't already, install the Cloud SDK.

    When prompted, choose the project that you selected or created above.

  7. If you already have the Cloud SDK installed, update it.

    gcloud components update
  8. Enable the Service Networking API for your project.
    Enable the Service Networking API
  9. Enable the Memorystore for Memcached API for your project.
    Enable the Memorystore for Memcached API

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
    
  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

  1. Connect to a Linux VM. For steps to connect to a Linux VM, see Quickstart Using a Linux VM. 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 variables 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.

Cleaning up

  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