如何管理 Azure Redis 缓存How to administer Azure Cache for Redis

本主题介绍如何为 Azure Redis 缓存实例执行管理任务,如重启计划更新This topic describes how to perform administration tasks such as rebooting and scheduling updates for your Azure Cache for Redis instances.


本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.


可通过“重新启动”边栏选项卡重新启动缓存的一个或多个节点。The Reboot blade allows you to reboot one or more nodes of your cache. 如果有缓存节点发生故障,此重新启动功能可用于测试应用程序的复原能力。This reboot capability enables you to test your application for resiliency if there is a failure of a cache node.


选择要重新启动的节点,并单击“重新启动” 。Select the nodes to reboot and click Reboot .


如果高级缓存启用了群集功能,则可选择要重新启动的缓存分片。If you have a premium cache with clustering enabled, you can select which shards of the cache to reboot.


如果要重新启动缓存的一个或多个节点,请选择所需节点,并单击“重新启动”。To reboot one or more nodes of your cache, select the desired nodes and click Reboot . 如果高级缓存启用了群集功能,请选择要重新启动的所需分片,然后单击“重新启动”。If you have a premium cache with clustering enabled, select the desired shards to reboot and then click Reboot . 几分钟后,所选节点将重新启动,再过几分钟后,又会回到联机状态。After a few minutes, the selected nodes reboot, and are back online a few minutes later.

对客户端应用程序的影响因用户重新启动的节点而有所不同。The impact on client applications varies depending on which nodes that you reboot.

  • - 重新启动主节点时,Azure Cache for Redis 会故障转移到副本节点,并将其提升为主节点。Master - When the primary node is rebooted, Azure Cache for Redis fails over to the replica node and promotes it to primary. 在此故障转移期间,可能会有一个较短的时间间隔无法连接到缓存。During this failover, there may be a short interval in which connections may fail to the cache.
  • 副本 - 重新启动副本节点时,通常不会影响缓存客户端。Replica - When the replica node is rebooted, there is typically no impact to cache clients.
  • 主和副本 - 同时重新启动这两个缓存节点时,缓存中的所有数据都会丢失,并且无法连接到缓存,直到主节点重新联机。Both primary and replica - When both cache nodes are rebooted, all data is lost in the cache and connections to the cache fail until the primary node comes back online. 如果已配置数据持久性,则在缓存重新联机时会还原最新备份,但在最新备份后发生的所有缓存写入都将丢失。If you have configured data persistence, the most recent backup is restored when the cache comes back online, but any cache writes that occurred after the most recent backup are lost.
  • 已启用群集的高级缓存的节点 - 重新启动已启用群集的高级缓存的一个或多个节点时,所选节点的行为与重新启动非群集缓存的相应节点时相同。Nodes of a premium cache with clustering enabled - When you reboot one or more nodes of a premium cache with clustering enabled, the behavior for the selected nodes is the same as when you reboot the corresponding node or nodes of a non-clustered cache.

重新启动常见问题解答Reboot FAQ

测试应用程序时应重新启动哪个节点?Which node should I reboot to test my application?

若要针对缓存的主节点故障测试应用程序的复原能力,请重新启动 节点。To test the resiliency of your application against failure of the primary node of your cache, reboot the Master node. 若要针对副本节点故障测试应用程序的复原能力,请重新启动“副本”节点。To test the resiliency of your application against failure of the replica node, reboot the Replica node. 若要针对缓存的总故障测试应用程序的复原能力,请同时重新启动这 两个 节点。To test the resiliency of your application against total failure of the cache, reboot Both nodes.

能否通过重新启动缓存来清除客户端连接?Can I reboot the cache to clear client connections?

能,如果重新启动缓存,则会清除所有客户端连接。Yes, if you reboot the cache all client connections are cleared. 当所有客户端连接均已用完(由于客户端应用程序中的逻辑错误或 Bug)时,重新启动很有用。Rebooting can be useful in the case where all client connections are used up due to a logic error or a bug in the client application. 每个定价层对于不同大小都有不同的客户端连接数限制,达到这些限制后,将不再接受客户端连接。Each pricing tier has different client connection limits for the various sizes, and once these limits are reached, no more client connections are accepted. 通过重新启动缓存可以清除所有客户端连接。Rebooting the cache provides a way to clear all client connections.


如果通过重新启动缓存来清除客户端连接,则一旦 Redis 节点重回联机状态,StackExchange.Redis 就会自动重新连接。If you reboot your cache to clear client connections, StackExchange.Redis automatically reconnects once the Redis node is back online. 如果未解决这一基本问题,客户端连接会继续用完。If the underlying issue is not resolved, the client connections may continue to be used up.

如果执行重新启动,是否会丢失缓存中的数据?Will I lose data from my cache if I do a reboot?

如果同时重新启动主节点和副本节点,则缓存中或该分片中(如果使用已启用群集的高级缓存)的所有数据都可能会丢失,但这种情况也不一定会发生。If you reboot both the Master and Replica nodes, all data in the cache (or in that shard if you are using a premium cache with clustering enabled) may be lost, but this is not guaranteed either. 如果已配置数据持久性,则在缓存重新联机时会还原最新备份,但在进行该备份后发生的所有缓存写入都将丢失。If you have configured data persistence, the most recent backup will be restored when the cache comes back online, but any cache writes that have occurred after the backup was made are lost.

如果只重新启动其中一个节点,数据通常不会丢失,但仍然存在丢失的可能。If you reboot just one of the nodes, data is not typically lost, but it still may be. 例如,如果重新启动主节点时正在进行缓存写入,则缓存写入的数据会丢失。For example if the primary node is rebooted and a cache write is in progress, the data from the cache write is lost. 发生数据丢失的另一种情况是,在重新启动一个节点时,另一个节点恰巧因故障而关闭。Another scenario for data loss would be if you reboot one node and the other node happens to go down due to a failure at the same time. 有关数据丢失的可能原因的详细信息,请参阅我在 Redis 中的数据发生了什么情况?For more information about possible causes for data loss, see What happened to my data in Redis?

能否使用 PowerShell、CLI 或其他管理工具重新启动缓存?Can I reboot my cache using PowerShell, CLI, or other management tools?

能,有关 PowerShell 说明,请参阅重新启动 Azure Redis 缓存Yes, for PowerShell instructions see To reboot an Azure Cache for Redis.

计划更新Schedule updates

使用“计划更新”边栏选项卡可以为缓存实例指定维护时段。The Schedule updates blade allows you to designate a maintenance window for your cache instance. 借助维护时段,可以控制在一周中的哪一天和哪个时间点更新托管缓存的 VM。A maintenance window allows you to control the day(s) and time(s) of a week during which the VM(s) hosting your cache can be updated. Azure Cache for Redis 将尽最大努力在定义的指定时间范围内启动和完成 Redis 服务器软件的更新。Azure Cache for Redis will make a best effort to start and finish updating Redis server software within the specified time window you define.


维护时段仅适用于 Redis 服务器更新,不适用于任何 Azure 更新或托管缓存的 VM 的操作系统更新。The maintenance window applies only to Redis server updates, and not to any Azure updates or updates to the operating system of the VMs that host the cache.


如果要指定维护时段,请勾选合适的日期,并指定每天的维护时段开始时间,最后再单击“确定”。To specify a maintenance window, check the desired days and specify the maintenance window start hour for each day, and click OK . 请注意,维护时段使用 UTC 时间。Note that the maintenance window time is in UTC.

更新的默认最小维护时段为 5 小时。The default, and minimum, maintenance window for updates is five hours. 此值不可以在 Azure 门户中配置,但可以在 PowerShell 中使用 New-AzRmRedisCacheScheduleEntry cmdlet 的 MaintenanceWindow 参数进行配置。This value is not configurable from the Azure portal, but you can configure it in PowerShell using the MaintenanceWindow parameter of the New-AzRedisCacheScheduleEntry cmdlet. 有关详细信息,请参阅是否可以使用 PowerShell、CLI 或其他管理工具管理计划的更新?For more information, see Can I manage scheduled updates using PowerShell, CLI, or other management tools?

计划更新常见问题解答Schedule updates FAQ

如果不使用计划更新功能,何时进行更新?When do updates occur if I don't use the schedule updates feature?

如果未指定维护时段,可以随时进行更新。If you don't specify a maintenance window, updates can be made at any time.

在计划性维护时段进行哪种类型的更新?What type of updates are made during the scheduled maintenance window?

仅在计划的维护时段进行 Redis 服务器更新。Only Redis server updates are made during the scheduled maintenance window. 维护时段不适用于 Azure 更新或 VM 操作系统更新。The maintenance window does not apply to Azure updates or updates to the VM operating system.

有关详细信息,请参阅能否使用 PowerShell、CLI 或其他管理工具管理计划的更新?Can I managed scheduled updates using PowerShell, CLI, or other management tools?

可以使用以下 PowerShell cmdlet 管理计划的更新:Yes, you can manage your scheduled updates using the following PowerShell cmdlets:

后续步骤Next steps

了解有关 Azure Cache for Redis 功能的详细信息。Learn more about Azure Cache for Redis features.