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

如何缩放 Azure Redis 缓存How to Scale Azure Redis Cache

Azure Redis 缓存具有不同的缓存产品/服务,使缓存大小和功能的选择更加灵活。Azure Redis Cache has different cache offerings, which provide flexibility in the choice of cache size and features. 如果创建缓存后,应用程序的要求发生更改,可以更改缓存的大小和定价层。After a cache is created, you can scale the size and the pricing tier of the cache if the requirements of your application change. 本文演示如何使用 Azure 门户以及 Azure PowerShell 和 Azure CLI 等工具来缩放缓存。This article shows you how to scale your cache using the Azure portal, and tools such as Azure PowerShell, and Azure CLI.

何时缩放When to scale

可以使用 Azure Redis 缓存的监视功能来监视缓存的运行状况和性能,并帮助确定何时缩放缓存。You can use the monitoring features of Azure Redis Cache to monitor the health and performance of your cache and help determine when to scale the cache.

可以监视以下指标以帮助确定是否需要进行缩放。You can monitor the following metrics to help determine if you need to scale.

  • Redis 服务器负载Redis Server Load
  • 内存用量Memory Usage
  • 网络带宽Network Bandwidth
  • CPU 使用率CPU Usage

如果确定缓存不再满足应用程序的要求,可以更改到应用程序所需的更大或更小缓存定价层。If you determine that your cache is no longer meeting your application's requirements, you can scale to a larger or smaller cache pricing tier that is right for your application. 有关确定应使用哪个缓存定价层的详细信息,请参阅我应当使用哪些 Redis 缓存产品/服务和大小For more information on determining which cache pricing tier to use, see What Redis Cache offering and size should I use.

缩放缓存Scale a cache

要缩放缓存,请在 Azure 门户浏览到缓存,并从“资源菜单”单击“缩放”。To scale your cache, browse to the cache in the Azure portal and click Scale from the Resource menu.

缩放

从“选择定价层”边栏选项卡选择所需的定价层,并单击“选择”。Select the desired pricing tier from the Select pricing tier blade and click Select.

定价层

可以扩展到不同定价层,但有以下限制:You can scale to a different pricing tier with the following restrictions:

  • 不能从较高的定价层缩放到较低的定价层。You can't scale from a higher pricing tier to a lower pricing tier.
    • 不能从高级缓存向下缩放到标准基本缓存。You can't scale from a Premium cache down to a Standard or a Basic cache.
    • 不能从标准缓存向下缩放到基本缓存。You can't scale from a Standard cache down to a Basic cache.
  • 可从基本缓存缩放到标准缓存,但不能同时更改大小。You can scale from a Basic cache to a Standard cache but you can't change the size at the same time. 如果需要不同大小,则可以执行后续缩放操作以缩放为所需大小。If you need a different size, you can do a subsequent scaling operation to the desired size.
  • 不能从基本缓存直接缩放到高级缓存。You can't scale from a Basic cache directly to a Premium cache. 首先在一个缩放操作中从基本缩放到标准,然后在后续的缩放操作中从标准缩放到高级First, scale from Basic to Standard in one scaling operation, and then from Standard to Premium in a subsequent scaling operation.
  • 不能从较大的大小减小为 C0 (250 MB)You can't scale from a larger size down to the C0 (250 MB) size.

当缓存缩放到新的定价层,会在“Redis 缓存”边栏选项卡中显示缩放状态。While the cache is scaling to the new pricing tier, a Scaling status is displayed in the Redis Cache blade.

扩展

缩放完成后,状态将从正在缩放更改为正在运行When scaling is complete, the status changes from Scaling to Running.

如何自动执行缩放操作How to automate a scaling operation

除了在 Azure 门户中缩放缓存实例以外,还可以使用 PowerShell cmdlet、Azure CLI 和 Microsoft Azure 管理库 (MAML) 进行缩放。In addition to scaling your cache instances in the Azure portal, you can scale using PowerShell cmdlets, Azure CLI, and by using the Microsoft Azure Management Libraries (MAML).

使用 PowerShell 进行缩放Scale using PowerShell

修改 SizeSkuShardCount 属性后,可以在 PowerShell 中使用 Set-AzureRmRedisCache cmdlet 缩放 Azure Redis 缓存实例。You can scale your Azure Redis Cache instances with PowerShell by using the Set-AzureRmRedisCache cmdlet when the Size, Sku, or ShardCount properties are modified. 以下示例演示了如何将名为 myCache 的缓存缩放为 2.5 GB 缓存。The following example shows how to scale a cache named myCache to a 2.5 GB cache.

Set-AzureRmRedisCache -ResourceGroupName myGroup -Name myCache -Size 2.5GB

有关使用 PowerShell 进行缩放的详细信息,请参阅使用 PowerShell 缩放 Redis 缓存For more information on scaling with PowerShell, see To scale a Redis cache using Powershell.

使用 Azure CLI 进行缩放Scale using Azure CLI

若要使用 Azure CLI 缩放 Azure Redis 缓存实例,请调用 azure rediscache set 命令并传入所需的配置更改,包括新大小、sku 或群集大小,具体取决于所需的缩放操作。To scale your Azure Redis Cache instances using Azure CLI, call the azure rediscache set command and pass in the desired configuration changes that include a new size, sku, or cluster size, depending on the desired scaling operation.

有关使用 Azure CLI 进行缩放的详细信息,请参阅更改现有 Redis 缓存的设置For more information on scaling with Azure CLI, see Change settings of an existing Redis Cache.

使用 MAML 进行缩放Scale using MAML

若要使用 Microsoft Azure 管理库 (MAML) 缩放 Azure Redis 缓存实例,请调用 IRedisOperations.CreateOrUpdate 并传入 RedisProperties.SKU.Capacity 的新大小。To scale your Azure Redis Cache instances using the Microsoft Azure Management Libraries (MAML), call the IRedisOperations.CreateOrUpdate method and pass in the new size for the RedisProperties.SKU.Capacity.

static void Main(string[] args)
{
    // For instructions on getting the access token, see
    // https://azure.microsoft.com/documentation/articles/cache-configure/#access-keys
    string token = GetAuthorizationHeader();

    TokenCloudCredentials creds = new TokenCloudCredentials(subscriptionId,token);

    RedisManagementClient client = new RedisManagementClient(creds);
    var redisProperties = new RedisProperties();

    // To scale, set a new size for the redisSKUCapacity parameter.
    redisProperties.Sku = new Sku(redisSKUName,redisSKUFamily,redisSKUCapacity);
    redisProperties.RedisVersion = redisVersion;
    var redisParams = new RedisCreateOrUpdateParameters(redisProperties, redisCacheRegion);
    client.Redis.CreateOrUpdate(resourceGroupName,cacheName, redisParams);
}

有关详细信息,请参阅使用 MAML 管理 Redis 缓存示例。For more information, see the Manage Redis Cache using MAML sample.

关于缩放的常见问题Scaling FAQ

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

可以向上缩放到高级缓存,或在其中向下缩放吗?Can I scale to, from, or within a Premium cache?

  • 不能从高级缓存向下缩放到基本标准定价层。You can't scale from a Premium cache down to a Basic or Standard pricing tier.
  • 可以从一个高级缓存定价层缩放到另一个高级缓存定价层。You can scale from one Premium cache pricing tier to another.
  • 不能从基本缓存直接缩放到高级缓存。You can't scale from a Basic cache directly to a Premium cache. 首先在一个缩放操作中从基本缩放到标准,然后在后续的缩放操作中从标准缩放到高级First, scale from Basic to Standard in one scaling operation, and then from Standard to Premium in a subsequent scaling operation.
  • 如果在创建高级缓存时启用了群集,则可以更改群集大小If you enabled clustering when you created your Premium cache, you can change the cluster size. 如果创建缓存时未启用群集功能,可以稍后进行配置。If your cache was created without clustering enabled, you can configure clustering at a later time.

    有关详细信息,请参阅 如何为高级 Azure Redis 缓存配置群集功能For more information, see How to configure clustering for a Premium Azure Redis Cache.

缩放后,我是否需要更改缓存名称或访问密钥?After scaling, do I have to change my cache name or access keys?

不需要,在缩放操作期间缓存名称和密钥不变。No, your cache name and keys are unchanged during a scaling operation.

缩放的工作原理?How does scaling work?

  • 基本缓存缩放为不同大小时,将关闭该缓存,同时使用新的大小预配一个新缓存。When a Basic cache is scaled to a different size, it is shut down and a new cache is provisioned using the new size. 在此期间,缓存不可用,且缓存中的所有数据都将丢失。During this time, the cache is unavailable and all data in the cache is lost.
  • 基本缓存缩放为标准缓存时,将预配副本缓存并将主缓存中的数据复制到副本缓存。When a Basic cache is scaled to a Standard cache, a replica cache is provisioned and the data is copied from the primary cache to the replica cache. 在缩放过程中,缓存仍然可用。The cache remains available during the scaling process.
  • 标准缓存缩放为不同大小或缩放到高级缓存时,将关闭其中一个副本,同时将其重新预配为新的大小,将数据转移,然后,在重新预配另一个副本之前,另一个副本将执行一次故障转移,类似于一个缓存节点发生故障时所发生的过程。When a Standard cache is scaled to a different size or to a Premium cache, one of the replicas is shut down and reprovisioned to the new size and the data transferred over, and then the other replica performs a failover before it is reprovisioned, similar to the process that occurs during a failure of one of the cache nodes.

在缩放过程中是否会丢失缓存中的数据?Will I lose data from my cache during scaling?

  • 基本缓存缩放为新的大小时,所有数据都将丢失,且在缩放操作期间缓存将不可用。When a Basic cache is scaled to a new size, all data is lost and the cache is unavailable during the scaling operation.
  • 基本缓存缩放为标准缓存时,通常将保留缓存中的数据。When a Basic cache is scaled to a Standard cache, the data in the cache is typically preserved.
  • 标准缓存扩展为更大大小或更大层,或者将高级缓存扩展为更大大小时,通常将保留所有数据。When a Standard cache is scaled to a larger size or tier, or a Premium cache is scaled to a larger size, all data is typically preserved. 标准高级缓存缩小到更小大小时,数据可能会丢失,具体取决于与缩放后的新大小相关的缓存中的数据量。When scaling a Standard or Premium cache down to a smaller size, data may be lost depending on how much data is in the cache related to the new size when it is scaled. 如果缩小时数据丢失,则使用 allkeys lru 逐出策略逐出密钥。If data is lost when scaling down, keys are evicted using the allkeys-lru eviction policy.

在缩放过程中,自定义数据库设置是否会受影响?Is my custom databases setting affected during scaling?

如果在缓存创建过程中为 databases 设置配置了自定义值,请记住,某些定价层具有不同的数据库限制If you configured a custom value for the databases setting during cache creation, keep in mind that some pricing tiers have different databases limits. 以下是在这种情况下缩放时的一些注意事项:Here are some considerations when scaling in this scenario:

  • 缩放到的定价层的 databases 限制低于当前层:When scaling to a pricing tier with a lower databases limit than the current tier:
    • 如果使用默认 databases 数(对于所有定价层来说均为 16),则不会丢失数据。If you are using the default number of databases, which is 16 for all pricing tiers, no data is lost.
    • 如果使用的是在要缩放到的层的限制内的自定义 databases 数,则将保留此 databases 设置并且不会丢失数据。If you are using a custom number of databases that falls within the limits for the tier to which you are scaling, this databases setting is retained and no data is lost.
    • 如果使用的是超出新层限制的自定义 databases 数,则 databases 设置将降低到新层的限制,并且已删除数据库中的所有数据都将丢失。If you are using a custom number of databases that exceeds the limits of the new tier, the databases setting is lowered to the limits of the new tier and all data in the removed databases is lost.
  • 所缩放到的定价层的 databases 限制等于或高于当前定价层时,将保留 databases 设置并且不会丢失数据。When scaling to a pricing tier with the same or higher databases limit than the current tier, your databases setting is retained and no data is lost.

虽然标准和高级缓存具有 99.9% 可用性 SLA,但没有数据丢失方面的 SLA。While Standard and Premium caches have a 99.9% SLA for availability, there is no SLA for data loss.

在缩放过程中,缓存是否可用?Will my cache be available during scaling?

  • 标准高级缓存在缩放操作期间保持可用。Standard and Premium caches remain available during the scaling operation. 但是,缩放标准和高级缓存时,以及从基本缓存缩放到标准缓存时,可能会发生连接故障。However, connection blips can occur while scaling Standard and Premium caches, and also while scaling from Basic to Standard caches. 这些连接故障预期为很小的故障,redis 客户端应能立即重新建立连接。These connection blips are expected to be small and redis clients should be able to re-establish their connection instantly.
  • 基本缓存在缩放为不同大小的操作期间处于脱机状态。Basic caches are offline during scaling operations to a different size. 基本缓存在从基本缩放到标准时仍然可用,但可能会出现较小的连接故障。Basic caches remain available when scaling from Basic to Standard but, may experience a small connection blip. 如果发生连接故障,redis 客户端应能立即重新建立连接。If a connection blip occurs, redis clients should be able to re-establish their connection instantly.

异地复制的缩放限制Scaling limitations with Geo-replication

向两个缓存之间添加异地复制链接后,便无法在群集中启动缩放操作或更改分片数。Once you have added a Geo-replication link between two caches, you will no longer be able to initiate a scaling operation or change the number of shards in a cluster. 若要发布这些命令,必须取消链接缓存。You must unlink the cache to issue these commands. 有关详细信息,请参阅配置异地复制For more information, see Configure Geo-replication.

不支持的操作Operations that are not supported

  • 不能从较高的定价层缩放到较低的定价层。You can't scale from a higher pricing tier to a lower pricing tier.
    • 不能从高级缓存向下缩放到标准基本缓存。You can't scale from a Premium cache down to a Standard or a Basic cache.
    • 不能从标准缓存向下缩放到基本缓存。You can't scale from a Standard cache down to a Basic cache.
  • 可从基本缓存缩放到标准缓存,但不能同时更改大小。You can scale from a Basic cache to a Standard cache but you can't change the size at the same time. 如果需要不同大小,则可以执行后续缩放操作以缩放为所需大小。If you need a different size, you can do a subsequent scaling operation to the desired size.
  • 不能从基本缓存直接缩放到高级缓存。You can't scale from a Basic cache directly to a Premium cache. 首先在一个缩放操作中从基本缩放到标准,然后在后续操作中从标准缩放到高级First scale from Basic to Standard in one scaling operation, and then scale from Standard to Premium in a subsequent operation.
  • 不能从较大的大小减小为 C0 (250 MB)You can't scale from a larger size down to the C0 (250 MB) size.

如果缩放操作失败,该服务将尝试还原操作并且缓存将还原为原始大小。If a scaling operation fails, the service tries to revert the operation, and the cache will revert to the original size.

缩放需要多长时间?How long does scaling take?

缩放大约需要 20 分钟,具体取决于缓存中的数据量。Scaling takes approximately 20 minutes, depending on how much data is in the cache.

如何判断缩放何时完成?How can I tell when scaling is complete?

在 Azure 门户中可以看到进行中的缩放操作。In the Azure portal, you can see the scaling operation in progress. 缩放完成后,缓存状态将更改为正在运行When scaling is complete, the status of the cache changes to Running.