您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

如何为高级 Azure Redis 缓存配置数据暂留How to configure data persistence for a Premium Azure Redis Cache

Azure Redis 缓存具有不同的缓存产品(包括高级层功能,如群集、暂留和虚拟网络支持),使缓存大小和功能的选择更加灵活。Azure Redis Cache has different cache offerings which provide flexibility in the choice of cache size and features, including Premium tier features such as clustering, persistence, and virtual network support. 本文介绍如何配置高级 Azure Redis 缓存实例中的暂留。This article describes how to configure persistence in a premium Azure Redis Cache instance.

有关其他高级缓存功能的信息,请参阅 Azure Redis 缓存高级层简介For information on other premium cache features, see Introduction to the Azure Redis Cache Premium tier.

什么是数据暂留?What is data persistence?

Redis 暂留可让你保留存储在 Redis 中的数据。Redis persistence allows you to persist data stored in Redis. 还可以获取快照并备份数据,以便在出现硬件故障时进行加载。You can also take snapshots and back up the data, which you can load in case of a hardware failure. 这相对于基本级别或标准级别是一项巨大优势,因为基本级别或标准级别将所有数据存储在内存中,在出现故障的情况下,如果缓存节点停机,则可能导致数据丢失。This is a huge advantage over Basic or Standard tier where all the data is stored in memory and there can be potential data loss in case of a failure where Cache nodes are down.

Azure Redis 缓存使用以下模型提供 Redis 暂留:Azure Redis Cache offers Redis persistence using the following models:

  • RDB 暂留 - 配置 RDB(Redis 数据库)暂留以后,Azure Redis 缓存会按照可配置的备份频率,将 Redis 缓存的快照以 Redis 二进制格式保留在磁盘上。RDB persistence - When RDB (Redis database) persistence is configured, Azure Redis Cache persists a snapshot of the Redis cache in a Redis binary format to disk based on a configurable backup frequency. 如果发生了灾难性事件,导致主缓存和副缓存都无法使用,则会使用最新快照重新构造缓存。If a catastrophic event occurs that disables both the primary and replica cache, the cache is reconstructed using the most recent snapshot. 详细了解 RDB 暂留的优点缺点Learn more about the advantages and disadvantages of RDB persistence.
  • AOF 暂留 - 配置 AOF(仅追加文件)暂留后,Azure Redis 缓存将每个写入操作保存到日志,此日志每秒至少保存到 Microsoft Azure 存储帐户一次。AOF persistence - When AOF (Append only file) persistence is configured, Azure Redis Cache saves every write operation to a log that is saved at least once per second into an Azure Storage account. 如果发生了灾难性事件,导致主缓存和副缓存都无法使用,则会使用存储的写入操作重新构造缓存。If a catastrophic event occurs that disables both the primary and replica cache, the cache is reconstructed using the stored write operations. 详细了解 AOF 暂留的优点缺点Learn more about the advantages and disadvantages of AOF persistence.

可在缓存创建过程中通过“新建 Redis 缓存”边栏选项卡或者在现有高级缓存的“资源”菜单上配置暂留。Persistence is configured from the New Redis Cache blade during cache creation and on the Resource menu for existing premium caches.

要创建高级缓存,请登录到 Azure 门户,并单击“新建” > “数据库” > “Redis 缓存”。To create a premium cache, sign-in to the Azure portal and click New > Databases > Redis Cache.

创建缓存

备注

除了在 Azure 门户中创建缓存以外,也可以使用 Resource Manager 模板、PowerShell 或 Azure CLI 创建。In addition to creating caches in the Azure portal, you can also create them using Resource Manager templates, PowerShell, or Azure CLI. 有关创建 Azure Redis 缓存的详细信息,请参阅创建缓存For more information about creating an Azure Redis Cache, see Create a cache.

若要配置高级功能,请先在“定价层”下拉列表中选择一个高级定价层。To configure premium features, first select one of the premium pricing tiers in the Pricing tier drop-down list. 若要详细了解每个定价层,请单击“查看全部定价详细信息”,并从“选择你的定价层”边栏选项卡中选择一个定价层。For more information about each pricing tier, click View full pricing details and select a pricing tier from the Choose your pricing tier blade.

选择定价层

选中某个高级定价层后,请单击“Redis 暂留”。Once a premium pricing tier is selected, click Redis persistence.

Redis 暂留

下一部分中的步骤介绍如何在新的高级缓存上配置 Redis 暂留。The steps in the next section describe how to configure Redis persistence on your new premium cache. 配置 Redis 暂留后,单击“创建”以创建具有 Redis 暂留的新高级版缓存。Once Redis persistence is configured, click Create to create your new premium cache with Redis persistence.

启用 Redis 暂留Enable Redis persistence

通过选择“RDB”或“AOF”暂留可在“Redis 数据暂留”边栏选项卡上启用 Redis 暂留。Redis persistence is enabled on the Redis data persistence blade by choosing either RDB or AOF persistence. 对于新缓存,可以按前一部分中所述,在创建缓存过程中访问此边栏选项卡。For new caches, this blade is accessed during the cache creation process, as described in the previous section. 对于现有缓存,可从缓存的“资源菜单”访问“Redis 数据暂留”边栏选项卡。For existing caches, the Redis data persistence blade is accessed from the Resource menu for your cache.

Redis 设置

配置 RDB 暂留Configure RDB persistence

若要启用 RDB 暂留,请单击“RDB”。To enable RDB persistence, click RDB. 若要在以前启用的高级缓存上禁用 RDB 暂留,请单击“禁用”。To disable RDB persistence on a previously enabled premium cache, click Disabled.

Redis RDB 暂留

若要配置备份间隔,请从下拉列表选择“备份频率”。To configure the backup interval, select a Backup Frequency from the drop-down list. 选项包括“15 分钟”、“30 分钟”、“60 分钟”、“6 小时”、“12 小时”和“24 小时”。Choices include 15 Minutes, 30 minutes, 60 minutes, 6 hours, 12 hours, and 24 hours. 在上一个备份操作成功完成以后,此时间间隔就会开始倒计时,同时会启动新的备份。This interval starts counting down after the previous backup operation successfully completes and when it elapses a new backup is initiated.

单击“存储帐户”以选择要使用的存储帐户,并从“存储密钥”下拉列表中选择要使用的“主密钥”或“辅助密钥”。Click Storage Account to select the storage account to use, and choose either the Primary key or Secondary key to use from the Storage Key drop-down. 必须选择与缓存处于相同区域的存储帐户,建议选择“高级存储”帐户,因为高级存储的吞吐量较高。You must choose a storage account in the same region as the cache, and a Premium Storage account is recommended because premium storage has higher throughput.

重要

如果重新生成了暂留帐户的存储密钥,必须从“存储密钥”下拉列表中重新配置所需密钥。If the storage key for your persistence account is regenerated, you must reconfigure the desired key from the Storage Key drop-down.

单击“确定”可保存暂留配置。Click OK to save the persistence configuration.

一旦备份频率间隔时间已过,则会启动下一次备份(或新缓存的首次备份)。The next backup (or first backup for new caches) is initiated once the backup frequency interval elapses.

配置 AOF 暂留Configure AOF persistence

若要启用 AOF 暂留,请单击“AOF”。To enable AOF persistence, click AOF. 若要在以前启用的高级缓存上禁用 AOF 暂留,请单击“禁用”。To disable AOF persistence on a previously enabled premium cache, click Disabled.

Redis AOF 暂留

若要配置 AOF 暂留,请指定“第一个存储帐户”。To configure AOF persistence, specify a First Storage Account. 此存储帐户必须与缓存处于相同区域,建议选择“高级存储”帐户,因为高级存储的吞吐量较高。This storage account must be in the same region as the cache, and a Premium Storage account is recommended because premium storage has higher throughput. 也可配置名为“第二个存储帐户”的其他存储帐户。You can optionally configure an additional storage account named Second Storage Account. 如果配置第二个存储帐户,写入副本缓存操作会写入到第二个存储帐户。If a second storage account is configured, the writes to the replica cache are written to this second storage account. 对于每个配置的存储帐户,请从“存储密钥”下拉列表选择要使用的“主密钥”或“辅助密钥”。For each configured storage account, choose either the Primary key or Secondary key to use from the Storage Key drop-down.

重要

如果重新生成了暂留帐户的存储密钥,必须从“存储密钥”下拉列表中重新配置所需密钥。If the storage key for your persistence account is regenerated, you must reconfigure the desired key from the Storage Key drop-down.

启用 AOF 暂留后,写入缓存操作会保存到指定的存储帐户(如果配置了第二个存储帐户,还可指定该帐户)。When AOF persistence is enabled, write operations to the cache are saved to the designated storage account (or accounts if you have configured a second storage account). 如果灾难性故障导致主缓存和副本缓存均无法使用,则使用存储的 AOF 日志重新生成缓存。In the event of a catastrophic failure that takes down both the primary and replica cache, the stored AOF log is used to rebuild the cache.

保留常见问题Persistence FAQ

以下列表包含有关 Azure Redis 缓存保留常见问题的解答。The following list contains answers to commonly asked questions about Azure Redis Cache persistence.

RDB 暂留RDB persistence

AOF 暂留AOF persistence

能否在此前已创建的缓存的基础上启用保留?Can I enable persistence on a previously created cache?

是的,可以在创建缓存时或者在现有高级缓存上配置 Redis 持久性。Yes, Redis persistence can be configured both at cache creation and on existing premium caches.

是否可以同时启用 AOF 暂留和 RDB 暂留?Can I enable AOF and RDB persistence at the same time?

不可以,只能分别启用 RDB 或 AOF,不能同时启用二者。No, you can enable only RDB or AOF, but not both at the same time.

应该选择哪个暂留模型?Which persistence model should I choose?

AOF 暂留将每个写入保存到日志,与 RDB 暂留相比,这对吞吐量有一些影响,因为 RDB 暂留基于配置的备份间隔保存备份,对性能产生的影响非常小。AOF persistence saves every write to a log, which has some impact on throughput, compared with RDB persistence which saves backups based on the configured backup interval, with minimal impact on performance. 如果主要目标是最大程度减少数据损失,并且可应付缓存吞吐量下降,请选择 AOF 暂留。Choose AOF persistence if your primary goal is to minimize data loss, and you can handle a decrease in throughput for your cache. 如果希望在缓存上保持最优吞吐量,但仍希望使用一种数据恢复机制,请选择 RDB 暂留。Choose RDB persistence if you wish to maintain optimal throughput on your cache, but still want a mechanism for data recovery.

有关使用 AOF 暂留时的性能详细信息,请参阅 AOF 暂留是否影响缓存吞吐量、延迟或性能?For more information on performance when using AOF persistence, see Does AOF persistence affect throughout, latency, or performance of my cache?

如果我缩放到不同大小并还原了缩放操作之前生成的备份,会发生什么情况?What happens if I have scaled to a different size and a backup is restored that was made before the scaling operation?

对于 RDB 暂留和 AOF 暂留:For both RDB and AOF persistence:

  • 如果缩放到更大的大小,则没有任何影响。If you have scaled to a larger size, there is no impact.
  • 如果缩放到更小的大小,并且自定义数据库设置大于新大小的数据库限制,则不会还原这些数据库中的数据。If you have scaled to a smaller size, and you have a custom databases setting that is greater than the databases limit for your new size, data in those databases isn't restored. 有关详细信息,请参阅在缩放过程中,自定义数据库设置是否会受影响?For more information, see Is my custom databases setting affected during scaling?
  • 如果缩放到更小的大小,并且更小的大小空间不足,无法容纳上次备份的所有数据,则在还原过程中,通常会使用 allkeys-lru 逐出策略逐出密钥。If you have scaled to a smaller size, and there isn't enough room in the smaller size to hold all of the data from the last backup, keys will be evicted during the restore process, typically using the allkeys-lru eviction policy.

创建缓存后是否可更改 RDB 备份频率?Can I change the RDB backup frequency after I create the cache?

可以,可在“Redis 数据暂留”边栏选项卡上更改 RDB 暂留的备份频率。Yes, you can change the backup frequency for RDB persistence on the Redis data persistence blade. 有关说明,请参阅配置 Redis 暂留For instructions, see Configure Redis persistence.

为何我的 RDB 备份频率为 60 分钟,而两次备份的间隔却超过 60 分钟?Why if I have an RDB backup frequency of 60 minutes there is more than 60 minutes between backups?

RDB 暂留备份频率间隔在先前备份过程已成功完成后才会开始。The RDB persistence backup frequency interval does not start until the previous backup process has completed successfully. 如果备份频率为 60 分钟,而备份过程需要 15 分钟才能成功完成,则在上一次备份开始以后,要再过 75 分钟才会开始下一次备份。If the backup frequency is 60 minutes and it takes a backup process 15 minutes to successfully complete, the next backup won't start until 75 minutes after the start time of the previous backup.

进行新备份以后,旧的 RDB 备份会发生什么情况?What happens to the old RDB backups when a new backup is made?

除最新备份外的所有 RDB 暂留备份会被自动删除。All RDB persistence backups except for the most recent one are automatically deleted. 这种删除可能不会即刻发生,但旧备份是不会无限期保留下去的。This deletion may not happen immediately but older backups are not persisted indefinitely.

是否应使用第二个存储帐户?When should I use a second storage account?

如果认为缓存上的设置操作高于预期,则应将第二个存储帐户用于 AOF 暂留。You should use a second storage account for AOF persistence when you believe you have higher than expected set operations on the cache. 设置辅助存储帐户有助于确保缓存不会达到存储带宽限制。Setting up the secondary storage account helps ensure your cache doesn't reach storage bandwidth limits.

AOF 暂留是否影响缓存吞吐量、延迟或性能?Does AOF persistence affect throughout, latency, or performance of my cache?

缓存低于最大负载(CPU 和服务器负载皆低于 90%)时,AOF 暂留对性能产生约 15% - 20% 的影响。AOF persistence affects throughput by about 15% – 20% when the cache is below maximum load (CPU and Server Load both under 90%). 缓存处于这些限制以内时不存在延迟问题。There should not be latency issues when the cache is within these limits. 但是,启用 AOF 时缓存将更快达到这些限制。However, the cache will reach these limits sooner with AOF enabled.

如何删除第二个存储帐户?How can I remove the second storage account?

可通过将第二个存储帐户设置为与第一个存储帐户相同的方式来删除 AOF 暂留辅助存储帐户。You can remove the AOF persistence secondary storage account by setting the second storage account to be the same as the first storage account. 有关说明,请参阅配置 AOF 暂留For instructions, see Configure AOF persistence.

什么是重写?重写对缓存有何影响?What is a rewrite and how does it affect my cache?

在 AOF 文件足够大时,重写会自动处于缓存上的队列中。When the AOF file becomes large enough, a rewrite is automatically queued on the cache. 重写使用创建当前数据集所需的最小操作集来重设 AOF 文件大小。The rewrite resizes the AOF file with the minimal set of operations needed to create the current data set. 重写期间会很快达到性能限制,尤其是在处理大型数据集时。During rewrites, expect to reach performance limits sooner especially when dealing with large datasets. AOF 文件越大,重写发生频率越低,但是如果发生则会需要较长时间。Rewrites occur less often as the AOF file becomes larger, but will take a significant amount of time when it happens.

缩放启用 AOF 的缓存时会出现什么情况?What should I expect when scaling a cache with AOF enabled?

如果缩放时的 AOF 文件非常大,则缩放操作所花时间应长于预期,因为在缩放结束后才重载文件。If the AOF file at the time of scaling is significantly large, then expect the scale operation to take longer than expected since it will be reloading the file after scaling has finished.

有关缩放的详细信息,请参阅如果我缩放到不同大小并还原了缩放操作之前生成的备份,会发生什么情况?For more information on scaling, see What happens if I have scaled to a different size and a backup is restored that was made before the scaling operation?

AOF 数据如何在存储中进行整理?How is my AOF data organized in storage?

AOF 文件中存储的数据在每个节点分为多个页 Blob,以便提升将数据保存至存储的性能。Data stored in AOF files is divided into multiple page blobs per node to increase performance of saving the data to storage. 下表介绍每个定价层使用的页 Blob 数量:The following table displays how many page blobs are used for each pricing tier:

高级层Premium tier BlobBlobs
P1P1 4 个/分片4 per shard
P2P2 8 个/分片8 per shard
P3P3 16 个/分片16 per shard
P4P4 20 个/分片20 per shard

启用群集时,缓存中的每个分片具有自己的页 Blob 集,如上表所示。When clustering is enabled, each shard in the cache has its own set of page blobs, as indicated in the previous table. 例如,具有 3 个分片的 P2 缓存在 24 个页 Blob 之间(每个分片 8 个页 Blob,共 3 个分片)分配其 AOF 文件。For example, a P2 cache with three shards distributes its AOF file across 24 page blobs (8 blobs per shard, with 3 shards).

重写后,存储中存在 2 个 AOF 文件集。After a rewrite, two sets of AOF files exist in storage. 重写在后台进行,并附加到第一个文件集,而重写期间发送至缓存的设置操作会附加到第二个文件集。Rewrites occur in the background and append to the first set of files, while set operations that are sent to the cache during the rewrite append to the second set. 重写期间会暂时存储备份以防发生故障,但是备份在重写结束后会立即删除。A backup is temporarily stored during rewrites in case of failure, but is promptly deleted after a rewrite finishes.

后续步骤Next steps

了解如何使用更多的高级版缓存功能。Learn how to use more premium cache features.