使用 Google Cloud 控制台创建 Memorystore for Redis 实例

了解如何创建新的 Memorystore for Redis 实例、连接该实例以及将其删除。

准备工作

  1. 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 (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

创建 Redis 实例

  1. 在 Google Cloud 控制台中,前往 Memorystore for Redis 页面。

    Memorystore for Redis

    如果此页面不可用,请启用或重新启用 Memorystore for Redis API。

    启用 API

  2. 点击创建实例

  3. 创建 Redis 实例页面中,为要创建的实例进行以下配置。

    • 实例 ID 字段中,输入 my-instance-1
    • 显示名称字段中,输入 My Quickstart Instance
    • 选择层级部分中,选择基本。与使用副本节点来备份数据的标准层级相反,此层级指定独立的 Redis 节点。
    • 容量字段中,输入 5。这会将您的实例容量设置为 5 GB。
    • 区域菜单中,选择 us-central1(爱荷华)
    • 网络菜单中,选择默认
    • 展开配置节点,然后从版本菜单中选择
      7.0(推荐)
  4. 点击创建实例

  5. 创建实例后,请按照以下步骤获取实例的 IP address

    1. 前往 Google Cloud 控制台中的 Memorystore for Redis 页面。
      Memorystore for Redis
    2. 点击实例的 ID:my-instance-1
    3. 连接属性下,记下实例的 IP address
    4. 另请记下实例的端口编号 6379

从 Compute Engine 虚拟机实例连接到 Redis 实例

您可以从任何具有支持的 RFC 1918 IP 地址且使用 Redis 实例的授权网络的 Compute Engine 虚拟机连接到 Redis 实例。

  1. 如果您还没有与 Redis 实例使用同一授权网络的 Compute Engine 虚拟机,请创建一个虚拟机并按照 Linux 虚拟机使用快速入门中的说明连接到该虚拟机。

  2. 使用 apt-get 安装 telnet

    sudo apt-get install telnet
    
  3. 从该终端通过 telnet 连接到 Redis 实例的 IP 地址,并将 variables 替换为适当的值。

    telnet instance-ip-address 6379
    

    如果成功,该命令将返回以下结果:

    Trying instance-ip-address…
    Connected to instance-ip-address
    
  4. 在 telnet 会话中,输入一些 Redis 命令:

    请输入:

    PING
    

    结果:

    PONG
    

    输入

    SET HELLO WORLD
    

    结果:

    +OK
    

    请输入:

    GET HELLO
    

    结果:

    $5
    WORLD
    

清理

为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。

为避免因本快速入门中使用的资源导致您的 Google Cloud 账号产生费用,请执行以下操作:

  1. 前往 Google Cloud 控制台中的 Memorystore for Redis 页面。
    Memorystore for Redis
  2. 点击要删除的实例的 ID。
  3. 点击删除按钮。
  4. 在出现的提示符处,输入实例 ID。
  5. 点击删除

后续步骤