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

对缓存读取和写入数据

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

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

查找缓存端点

Amazon Web Services 管理控制台

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

  1. 登录 Amazon Web Services 管理控制台 并打开 Amazon ElastiCache 控制台(https://console.aws.amazon.com/elasticache/)。

  2. 在控制台左侧的导航窗格中,选择 Valkey 缓存 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 实例并连接到集群。在以下示例中,您使用 valkey-cli 实用工具连接到集群。可使用以下命令连接到缓存(注:将 cache-endpoint 替换为您在上一步中检索到的端点)。

src/valkey-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 实例并连接到集群。在以下示例中,您使用 valkey-cli 实用工具连接到集群。可使用以下命令连接到缓存。打开命令提示符,切换到 Valkey 目录并运行命令(注:将 Cache_Endpoint 替换为您在上一步中检索到的端点)。

c:\Redis>valkey-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"

您现在可以继续执行(可选)清除