第 2 步:对缓存读取和写入数据 - 亚马逊 ElastiCache (Redis OSS)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

第 2 步:对缓存读取和写入数据

此部分假设您已创建了 Amazon EC2 实例并可以连接到该实例。有关如何执行此操作的说明,请参阅 Amazon EC2 入门指南

此部分还假设您已为从中连接到缓存的 EC2 实例设定 VPC 访问权限和安全组设置,并已在 EC2 实例上设置 redis-cli。有关该步骤的更多信息,请参阅设置

查找缓存端点

Amazon Web Services Management Console

要使用 ElastiCache 控制台查找缓存的终端节点,请执行以下操作:

  1. 登录 Amazon Web Services Management Console 并打开亚马逊 ElastiCache 控制台,网址为 https://console.aws.amazon.com/elasticache/

  2. 在控制台左侧的导航窗格中,选择 Redis OSS 缓存

  3. 在控制台的右侧,单击刚刚创建的缓存的名称。

  4. 缓存详细信息中,找到并复制缓存端点。

Amazon CLI

以下 Amazon CLI 示例说明如何使用 describe-serverless-caches 命令查找新缓存的终端节点。运行命令后,查找“端点”字段。

Linux

aws elasticache describe-serverless-caches \ --serverless-cache-name CacheName

Windows

aws elasticache describe-serverless-caches ^ --serverless-cache-name CacheName

现在您有了所需的端点,便可以登录到您的 EC2 实例并连接到集群。在以下示例中,您使用 redis-cli 实用工具连接到集群。可使用以下命令连接到缓存(注:将 cache-endpoint 替换为您在上一步中检索到的端点)。

src/redis-cli -h cache-endpoint --tls -p 6379 set a "hello" // Set key "a" with a string value and no expiration OK get a // Get value for key "a" "hello"

现在您有了所需的端点,便可以登录到您的 EC2 实例并连接到集群。在以下示例中,您使用 redis-cli 实用工具连接到集群。可使用以下命令连接到缓存。打开命令提示符并切换到 Redis OSS 目录并运行命令(注意:将 Cache_Endpoint 替换为您在上一步中检索到的终端节点)。

c:\Redis>redis-cli -h Redis_Cluster_Endpoint --tls -p 6379 set a "hello" // Set key "a" with a string value and no expiration OK get a // Get value for key "a" "hello"

您现在可以继续执行第 3 步:(可选)清除