設定 Premium Azure Cache for Redis 實例的資料持續性Configure data persistence for a Premium Azure Cache for Redis instance

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 Cache for Redis 使用下列模型提供 Redis 持續性:Azure Cache for Redis offers Redis persistence using the following models:

  • RDB 持續性 - 設定 RDB (Redis 資料庫) 持續性後,Azure Cache for Redis 會依據可設定的備份頻率,在磁碟中保存一份 Redis 二進位格式的 Azure Cache for Redis 快照集。RDB persistence - When RDB (Redis database) persistence is configured, Azure Cache for Redis persists a snapshot of the Azure Cache for Redis 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 Cache for Redis 會將每個寫入作業儲存至記錄,而此記錄則會每秒至少一次儲存至 Azure 儲存體帳戶。AOF persistence - When AOF (Append only file) persistence is configured, Azure Cache for Redis 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 的資料寫入您所擁有和管理的 Azure 儲存體帳戶。Persistence writes Redis data into an Azure Storage account that you own and manage. 您可以在快取建立期間,以及在現有 premium 快取的 [資源] 功能表 上,設定 新的 Azure Cache for Redis 分頁。You can configure from the New Azure Cache for Redis blade during cache creation and on the Resource menu for existing premium caches.

注意

Azure 儲存體會在保存資料時自動將資料加密。Azure Storage automatically encrypts data when it is persisted. 您可以使用自己的金鑰進行加密。You can use your own keys for the encryption. 如需詳細資訊,請參閱 使用 Azure Key Vault 的客戶管理金鑰For more information, see Customer-managed keys with Azure Key Vault.

設定資料持續性Set up data persistence

  1. 若要建立 premium 快取,請登入 Azure 入口網站 ,然後選取 [ 建立資源]。To create a premium cache, sign in to the Azure portal and select Create a resource. 除了在 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 Cache for Redis 的詳細資訊,請參閱建立快取For more information about creating an Azure Cache for Redis, see Create a cache.

    建立資源。

  2. 在 [新增] 頁面上選取 [資料庫] ,然後選取 [Azure Cache for Redis] 。On the New page, select Databases and then select Azure Cache for Redis.

    選取 Azure Cache for Redis。

  3. 在 [ 新的 Redis 快取] 頁面上,設定新 premium 快取的設定。On the New Redis Cache page, configure the settings for your new premium cache.

    設定Setting 建議的值Suggested value 描述Description
    DNS 名稱DNS name 輸入全域唯一名稱。Enter a globally unique name. 快取名稱必須是介於1到63個字元之間的字串,其中只包含數位、字母或連字號。The cache name must be a string between 1 and 63 characters that contain only numbers, letters, or hyphens. 名稱的開頭和結尾必須是數字或字母,且不可包含連續的連字號。The name must start and end with a number or letter, and can't contain consecutive hyphens. 您的快取執行個體 主機名稱 將是 <DNS name>.redis.cache.windows.netYour cache instance's host name will be <DNS name>.redis.cache.windows.net.
    訂用帳戶Subscription 下拉式清單,然後選取您的訂用帳戶。Drop-down and select your subscription. 這個新的 Azure Cache for Redis 執行個體建立所在的訂用帳戶。The subscription under which to create this new Azure Cache for Redis instance.
    資源群組Resource group 下拉式清單並選取資源群組,或選取 [ 建立新 的],然後輸入新的資源組名。Drop-down and select a resource group, or select Create new and enter a new resource group name. 用來建立快取和其他資源的資源群組名稱。Name for the resource group in which to create your cache and other resources. 將所有的應用程式資源放在一個資源群組中,您將可輕鬆地一併管理或刪除這些資源。By putting all your app resources in one resource group, you can easily manage or delete them together.
    位置Location 下拉式清單並選取位置。Drop-down and select a location. 選取其他將使用快取的服務附近的區域Select a region near other services that will use your cache.
    快取類型Cache type 下拉式清單,並選取高階快取來設定 premium 功能。Drop-down and select a premium cache to configure premium features. 如需詳細資訊,請參閱 Azure Cache for Redis 定價For details, see Azure Cache for Redis pricing. 快取的可用大小、效能和功能取決於定價層。The pricing tier determines the size, performance, and features that are available for the cache. 如需詳細資訊,請參閱 Azure Cache for Redis 概觀For more information, see Azure Cache for Redis Overview.
  4. 選取 [網路] 索引標籤,或按一下頁面底部的 [網路] 按鈕。Select the Networking tab or click the Networking button at the bottom of the page.

  5. 在 [網路功能] 索引標籤中,選取您的連線方法。In the Networking tab, select your connectivity method. 對於高階快取實例,您可以透過公用 IP 位址或服務端點公開連線,或是使用私人端點私下進行連線。For premium cache instances, you can connect either publicly, via Public IP addresses or service endpoints, or privately, using a private endpoint.

  6. 選取頁面底部的 [下一步:進階] 索引標籤,或按一下頁面底部的 [下一步:進階] 按鈕。Select the Next: Advanced tab or click the Next: Advanced button on the bottom of the page.

  7. 在高階快取實例的 [ Advanced (高階)] 索引標籤中,設定非 TLS 埠、叢集和資料持續性的設定。In the Advanced tab for a premium cache instance, configure the settings for non-TLS port, clustering, and data persistence. 如果是資料持續性,您可以選擇 RDBAOF 持續性。For data persistence, you can choose either RDB or AOF persistence.

  8. 若要啟用 RDB 持續性,請按一下 rdb 並進行設定。To enable RDB persistence, click RDB and configure the settings.

    設定Setting 建議的值Suggested value 描述Description
    備份頻率Backup Frequency 下拉式清單並選取備份間隔,選項包括 15 分鐘30 分鐘60 分鐘6 小時12 小時24 小時Drop-down and select a backup interval, 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.
    儲存體帳戶Storage Account 下拉式清單,然後選取您的儲存體帳戶。Drop-down and select your storage account. 您必須選擇與快取位於相同區域和訂用帳戶中的儲存體帳戶,而且建議使用 進階儲存體 帳戶,因為 Premium 儲存體有更高的輸送量。You must choose a storage account in the same region and subscription as the cache, and a Premium Storage account is recommended because premium storage has higher throughput.
    儲存體金鑰Storage Key 下拉式清單,並選擇要使用的 主要金鑰次要金鑰Drop-down and choose either the Primary key or Secondary key to use. 如果重新產生了永續性帳戶的儲存體金鑰,您必須從 [儲存體金鑰] 下拉式清單中重新設定所需的金鑰。If the storage key for your persistence account is regenerated, you must reconfigure the desired key from the Storage Key drop-down.

    當備份頻率間隔過期時,就會起始第一個備份。The first backup is initiated once the backup frequency interval elapses.

    注意

    當 RDB 檔案備份到儲存體時,它們會以分頁 blob 的形式儲存。When RDB files are backed up to storage, they are stored in the form of page blobs.

  9. 若要啟用 AOF 持續性,請按一下 [ AOF ] 並進行設定。To enable AOF persistence, click AOF and configure the settings.

    設定Setting 建議的值Suggested value 描述Description
    第一個儲存體帳戶First Storage Account 下拉式清單,然後選取您的儲存體帳戶。Drop-down and select your storage account. 此儲存體帳戶必須與快取位於相同的區域和訂用帳戶,而且建議使用 進階儲存體 帳戶,因為 Premium 儲存體有更高的輸送量。This storage account must be in the same region and subscription as the cache, and a Premium Storage account is recommended because premium storage has higher throughput.
    第一個儲存體金鑰First Storage Key 下拉式清單,並選擇要使用的 主要金鑰次要金鑰Drop-down and choose either the Primary key or Secondary key to use. 如果重新產生了永續性帳戶的儲存體金鑰,您必須從 [儲存體金鑰] 下拉式清單中重新設定所需的金鑰。If the storage key for your persistence account is regenerated, you must reconfigure the desired key from the Storage Key drop-down.
    第二個儲存體帳戶Second Storage Account (選擇性的) 下拉式清單,然後選取您的次要儲存體帳戶。(Optional) Drop-down and select your secondary storage account. 您可以選擇性地設定額外的儲存體帳戶。You can optionally configure an additional storage account. 如果設定第二個儲存體帳戶,複本快取的寫入內容會寫入至此第二個儲存體帳戶。If a second storage account is configured, the writes to the replica cache are written to this second storage account.
    第二個儲存體金鑰Second Storage Key (選擇性) 下拉式清單,並選擇要使用的 主要金鑰次要金鑰(Optional) Drop-down and choose either the Primary key or Secondary key to use. 如果重新產生了永續性帳戶的儲存體金鑰,您必須從 [儲存體金鑰] 下拉式清單中重新設定所需的金鑰。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.

  10. 選取頁面底部的 [下一步:標記] 索引標籤,或按一下頁面底部的 [下一步:標記] 按鈕。Select the Next: Tags tab or click the Next: Tags button at the bottom of the page.

  11. 在 [標記] 索引標籤中,如果您想要分類資源,可以選擇性地輸入名稱和值。Optionally, in the Tags tab, enter the name and value if you wish to categorize the resource.

  12. 選取 [檢閱 + 建立]。Select Review + create. 您會移至 [檢閱 + 建立] 索引標籤,其中 Azure 會驗證您的組態。You're taken to the Review + create tab where Azure validates your configuration.

  13. 出現綠色的「通過驗證」訊息之後,請選取 [建立]。After the green Validation passed message appears, select Create.

建立快取需要一些時間。It takes a while for the cache to create. 您可以在 Azure Cache for Redis 的 [概觀] 頁面上監視進度。You can monitor progress on the Azure Cache for Redis Overview page. 當 [狀態] 顯示為 [執行中] 時,表示快取已可供使用。When Status shows as Running, the cache is ready to use.

永續性常見問題集Persistence FAQ

下列清單包含 Azure Cache for Redis 持續性相關常見問題的解答。The following list contains answers to commonly asked questions about Azure Cache for Redis 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 持續性根據所設定的備份間隔儲存備份,因此對效能的影響很低。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.

我可以在兩個不同的快取中使用相同的儲存體帳戶來持續保存嗎?Can I use the same storage account for persistence across two different caches?

是,您可以在兩個不同的快取中使用相同的儲存體帳戶來持續保存Yes, you can use the same storage account for persistence across two different caches

在建立快取之後,可以變更 RDB 備份頻率嗎?Can I change the RDB backup frequency after I create the cache?

是,您可以在 資料持續 性分頁上變更 RDB 持續性的備份頻率。Yes, you can change the backup frequency for RDB persistence on the 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. 若為現有的快取,則會從快取的 [資源] 功能表 存取 資料持續 性分頁。For existing caches, the Data persistence blade is accessed from the Resource menu for your cache. 若要停用 AOF 持續性,請按一下 [ 停用]。To disable AOF persistence, click Disabled.

什麼是重寫,其對快取有何影響?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. 例如,具有三個分區的 P2 快取會將其 AOF 檔案散發到 24 個分頁 Blob (3 個分區,所以每個分區 8 個 Blob)。For example, a P2 cache with three shards distributes its AOF file across 24 page blobs (8 blobs per shard, with 3 shards).

重寫後,儲存體中會有兩組 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.

要在資料持續性中使用的儲存體需要付費嗎?Will I be charged for the storage being used in Data Persistence?

是,您將會依據所使用儲存體帳戶的定價模型,支付所使用的儲存體費用。Yes, you will be charged for the storage being used as per the pricing model of the storage account being used.

下一步Next steps

深入瞭解 Azure Cache for Redis 功能。Learn more about Azure Cache for Redis features.