This page describes how to create a new Memorystore for Redis instance, connect to it, and then delete it.
Before you begin
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
- If you haven't already, install the Cloud SDK.
When prompted, choose the project that you selected or created above.
If you already have the Cloud SDK installed, update it.
gcloud components update
Creating a Memorystore for Redis instance
To create a Memorystore for Redis instance:
- Open a terminal window.
Set the project you'd like to create your instance in as the default project in
gcloudby entering the following command:
gcloud config set core/project PROJECT_ID
Enter the following command to create a 2 GiB Basic Tier Redis instance in the
gcloud redis instances create myinstance --size=2 --region=us-central1 \ --redis-version=redis_5_0
After the instance is created, enter the
describecommand to get the IP address and port of the instance:
gcloud redis instances describe myinstance --region=us-central1
gcloudreturns the following:
authorizedNetwork: projects/my-project/global/networks/default createTime: '2018-04-09T21:47:56.824081Z' currentLocationId: us-central1-a host: 10.0.0.27 locationId: us-central1-a memorySizeGb: 2 name: projects/my-project/locations/us-central1/instances/myinstance networkThroughputGbps: 2 port: 6379 redisVersion: REDIS_4_0 reservedIpRange: 10.0.0.24/29 state: READY tier: BASIC
You'll use the
portvalues to connect to the instance.
Connecting to the Redis instance from a Compute Engine VM
You can connect to the Redis instance from any Compute Engine VM instance located within the same project, region and network as the Redis instance.
If you don't already have a Compute Engine VM in the same project, region, and network as your Redis instance, create one and connect to it by following Quickstart using a Linux VM.
sudo apt-get install telnet
From the terminal, telnet to the IP address of the Redis instance, replacing variables with appropriate values.
telnet instance-ip-address 6379
If successful, the command will return this result:
Trying instance-ip-address… Connected to instance-ip-address
In the telnet session, enter some Redis commands:
SET HELLO WORLD
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 redis instances delete myinstance --region=us-central1
Yto confirm the instance to delete:
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]
gcloudreturns the following response:
Deleted instance [myinstance].
- Learn more about creating and managing instances.
- Learn about other ways to connect to your Redis instance.
- Learn about the characteristics of a Redis instance.