Create a Memorystore for Redis instance by using the gcloud CLI

Learn how to create a Memorystore for Redis instance, connect to it, and then deleteit.


To follow step-by-step guidance for this task directly in the Google Cloud console, clickGuide me:

Guide me


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.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Memorystore for Redis API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  7. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Memorystore for Redis API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  10. If you haven't already,install the Google Cloud CLI.

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

  11. If you already have the Google Cloud CLI installed, then update it.

    gcloud components update

Required roles

To get the permissions that you need to create a Memorystore for Redis instance, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Create a Memorystore for Redis instance

In this section, you create a 2-GB Memorystore for Redis instance that'slocated in theus-central1 region and is in the Basic tier. For moreinformation about tiers, seeRedis tier capabilities.

  1. Open a terminal window.
  2. To set the project that you want to create your instance in as the defaultproject, enter the following command:

    gcloud config set core/projectPROJECT_ID
  3. To create a 2 GiB Basic Tier Redis instance in theus-central1 region,enter the following command:

    gcloud redis instances create myinstance --size=2 --region=us-central1 \--redis-version=redis_6_x
  4. After you create the instance, to get the IP address and port number of theinstance, enter the following command:

    gcloud redis instances describe myinstance --region=us-central1

    If you can access to the instance, then the command returns this result:

    authorizedNetwork: projects/my-project/global/networks/defaultcreateTime: '2018-04-09T21:47:56.824081Z'currentLocationId: us-central1-ahost: 10.0.0.27locationId: us-central1-amemorySizeGb: 2name: projects/my-project/locations/us-central1/instances/myinstancenetworkThroughputGbps: 2port: 6379redisVersion: REDIS_6_XreservedIpRange: 10.0.0.24/29state: READYtier: BASIC

  5. Make a note of your instance'shost andport values. You need thesevalues to connect to the instance.

Connect to the Memorystore for Redis instance from a Compute Engine VM

You can connect to the Memorystore for Redis instance from any Compute EngineVM that uses the instance's authorized network with asupported RFC 1918 IP address.

  1. If you don't have a Compute Engine VM that uses that same authorizednetwork as your instance, then create one and connect to the VM by using SSH. Todo this, follow the steps inCreate a Linux VM instance in Compute Engine.

  2. Useapt-get to installtelnet:

    sudo apt-get install telnet
  3. From the terminal, telnet to the IP address of the instance. ReplaceVARIABLES with appropriate values.

    telnetINSTANCE_IP_ADDRESS 6379

    If you can connect to the instance, then the command returns this result:

    TryingINSTANCE_IP_ADDRESS…Connected toINSTANCE_IP_ADDRESS
  4. In the telnet session, enter some Redis commands:

    Enter:

    PING

    Result:

    PONG

    Enter

    SET HELLO WORLD

    Result:

    +OK

    Enter:

    GET HELLO

    Result:

    $5WORLD

Clean up

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

  1. To delete the instance, enter the following command:

    gcloud redis instances delete myinstance --region=us-central1
  2. To confirm the deletion, enterY:

    You are about to delete instance [myinstance] in [us-central1].Any associated data will be lost.Do you want to continue (Y/n)? YDelete request issued for: [myinstance]

    If you can delete to the instance, then the command returns this result:

    Deleted instance [myinstance].

  3. Optional. If you created a Compute Engine VM for this quickstart,thendelete it.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.