使用 Azure PowerShell 管理 Azure Redis 缓存Manage Azure Cache for Redis with Azure PowerShell
备注
本文进行了更新,以便使用新的 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 PowerShell。For Az module installation instructions, see Install Azure PowerShell.
本主题说明如何执行创建、更新和缩放 Azure Redis 缓存实例等常见任务、如何重新生成访问密钥,以及如何查看有关缓存的信息。This topic shows you how to perform common tasks such as create, update, and scale your Azure Cache for Redis instances, how to regenerate access keys, and how to view information about your caches. 有关 Azure Redis 缓存 PowerShell cmdlet 的完整列表,请参阅 Azure Redis 缓存 cmdlet。For a complete list of Azure Cache for Redis PowerShell cmdlets, see Azure Cache for Redis cmdlets.
备注
Azure 提供了可以用来创建和处理资源的两个不同部署模型:Azure 资源管理器部署模型和经典部署模型。Azure has two different deployment models you can use to create and work with resources: Azure Resource Manager and classic. 本文介绍了资源管理器部署模型的使用。This article covers the use of the Resource Manager deployment model. 对于新部署,建议使用资源管理器部署模型而非经典部署模型。We recommend the Resource Manager deployment model for new deployments instead of the classic deployment model.
有关经典部署模型的详细信息,请参阅 Azure 资源管理器与经典部署:了解部署模型和资源状态。For more information about the classic deployment model, see Azure Resource Manager vs. classic deployment: Understand deployment models and the state of your resources.
先决条件Prerequisites
如果已安装 Azure PowerShell,则必须确保安装的是 Azure PowerShell 版本 1.0.0 或更高版本。If you have already installed Azure PowerShell, you must have Azure PowerShell version 1.0.0 or later. 可以使用此命令在 Azure PowerShell 命令提示符下查看已安装的 Azure PowerShell 版本。You can check the version of Azure PowerShell that you have installed with this command at the Azure PowerShell command prompt.
Get-Module Az | format-table version
首先,必须使用以下命令登录到 Azure。First, you must log in to Azure with this command.
Connect-AzAccount -Environment AzureChinaCloud
在 Azure 登录对话框中指定 Azure 帐户的电子邮件地址及其密码。Specify the email address of your Azure account and its password in the Azure sign-in dialog.
接下来,如果有多个 Azure 订阅,则需要设置 Azure 订阅。Next, if you have multiple Azure subscriptions, you need to set your Azure subscription. 若要查看当前订阅的列表,请运行以下命令。To see a list of your current subscriptions, run this command.
Get-AzSubscription | sort SubscriptionName | Select SubscriptionName
若要指定订阅,请运行以下命令。To specify the subscription, run the following command. 在以下示例中,订阅名为 ContosoSubscription
。In the following example, the subscription name is ContosoSubscription
.
Select-AzSubscription -SubscriptionName ContosoSubscription
在可以将 Windows PowerShell 与 Azure Resource Manager 一起使用之前,需要具备以下项:Before you can use Windows PowerShell with Azure Resource Manager, you need the following:
- Windows PowerShell 3.0 版或 4.0 版。Windows PowerShell, Version 3.0 or 4.0. 若要查找 Windows PowerShell 的版本,请键入:
$PSVersionTable
并验证PSVersion
的值是否为 3.0 或 4.0。To find the version of Windows PowerShell, type:$PSVersionTable
and verify the value ofPSVersion
is 3.0 or 4.0. 若要安装兼容版本,请参阅 Windows Management Framework 3.0。To install a compatible version, see Windows Management Framework 3.0.
要获取你在本教程中看到的任何 cmdlet 的详细帮助,请使用 Get-Help cmdlet。To get detailed help for any cmdlet you see in this tutorial, use the Get-Help cmdlet.
Get-Help <cmdlet-name> -Detailed
例如,若要获取有关 New-AzRedisCache
cmdlet 的帮助,请键入:For example, to get help for the New-AzRedisCache
cmdlet, type:
Get-Help New-AzRedisCache -Detailed
若要在 Azure 中国云中创建缓存,请使用以下位置之一。To create a cache in the Azure China Cloud, use one of the following locations.
- 中国东部China East
- 中国北部China North
- 中国东部 2China East 2
- 中国北部 2China North 2
有关 Azure 中国云的详细信息,请参阅 由中国 21Vianet 运营的 AzureChinaCloud for Azure。For more information about the Azure China Cloud, see AzureChinaCloud for Azure operated by 21Vianet in China.
Azure Redis 缓存 PowerShell 使用的属性Properties used for Azure Cache for Redis PowerShell
下表包含使用 Azure PowerShell 创建和管理 Azure Redis 缓存实例时常用的参数的属性和说明。The following table contains properties and descriptions for commonly used parameters when creating and managing your Azure Cache for Redis instances using Azure PowerShell.
参数Parameter | 说明Description | 默认Default |
---|---|---|
名称Name | 缓存的名称Name of the cache | |
位置Location | 缓存的位置Location of the cache | |
ResourceGroupNameResourceGroupName | 要在其中创建缓存的资源组名称Resource group name in which to create the cache | |
大小Size | 缓存的大小。The size of the cache. 有效值是:P1、P2、P3、P4、C0、C1、C2、C3、C4、C5、C6、250MB、1GB、2.5GB、6GB、13GB、26GB、53GBValid values are: P1, P2, P3, P4, C0, C1, C2, C3, C4, C5, C6, 250MB, 1GB, 2.5GB, 6GB, 13GB, 26GB, 53GB | 1GB1GB |
ShardCountShardCount | 在启用群集的情况下创建高级缓存时要创建的分片数目。The number of shards to create when creating a premium cache with clustering enabled. 有效值是:1、2、3、4、5、6、7、8、9、10Valid values are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 | |
SKUSKU | 指定缓存的 SKU。Specifies the SKU of the cache. 有效值是:Basic、Standard、PremiumValid values are: Basic, Standard, Premium | 标准Standard |
RedisConfigurationRedisConfiguration | 指定 Redis 配置设置。Specifies Redis configuration settings. 有关每个设置的详细信息,请参阅以下 RedisConfiguration 属性表。For details on each setting, see the following RedisConfiguration properties table. | |
EnableNonSslPortEnableNonSslPort | 指出是否启用非 SSL 端口。Indicates whether the non-SSL port is enabled. | FalseFalse |
MaxMemoryPolicyMaxMemoryPolicy | 此参数已弃用 - 请改用 RedisConfiguration。This parameter has been deprecated - use RedisConfiguration instead. | |
StaticIPStaticIP | 在 VNET 中托管缓存时,指定缓存在子网中的唯一 IP 地址。When hosting your cache in a VNET, specifies a unique IP address in the subnet for the cache. 如果未提供此值,系统将从子网中为你选择一个。If not provided, one is chosen for you from the subnet. | |
子网Subnet | 在 VNET 中托管缓存时,指定要在其中部署缓存的子网。When hosting your cache in a VNET, specifies the name of the subnet in which to deploy the cache. | |
VirtualNetworkVirtualNetwork | 在 VNET 中托管缓存时,指定要在其中部署缓存的 VNET 的资源 ID。When hosting your cache in a VNET, specifies the resource ID of the VNET in which to deploy the cache. | |
KeyTypeKeyType | 指定续订访问密钥时要重新生成哪个访问密钥。Specifies which access key to regenerate when renewing access keys. 有效值是:Primary、SecondaryValid values are: Primary, Secondary |
RedisConfiguration 属性RedisConfiguration properties
属性Property | 说明Description | 定价层Pricing tiers |
---|---|---|
rdb-backup-enabledrdb-backup-enabled | 是否已启用 Redis 数据暂留Whether Redis data persistence is enabled | 仅限高级版Premium only |
rdb-storage-connection-stringrdb-storage-connection-string | Redis 数据暂留存储帐户的连接字符串The connection string to the storage account for Redis data persistence | 仅限高级版Premium only |
rdb-backup-frequencyrdb-backup-frequency | Redis 数据暂留的备份频率The backup frequency for Redis data persistence | 仅限高级版Premium only |
maxmemory-reservedmaxmemory-reserved | 为非缓存进程配置预留的内存Configures the memory reserved for non-cache processes | 标准版和高级版Standard and Premium |
maxmemory-policymaxmemory-policy | 为缓存配置逐出策略Configures the eviction policy for the cache | 所有定价层All pricing tiers |
notify-keyspace-eventsnotify-keyspace-events | 配置 keyspace 通知Configures keyspace notifications | 标准版和高级版Standard and Premium |
hash-max-ziplist-entrieshash-max-ziplist-entries | 为较小的聚合数据类型配置 内存优化Configures memory optimization for small aggregate data types | 标准版和高级版Standard and Premium |
hash-max-ziplist-valuehash-max-ziplist-value | 为较小的聚合数据类型配置 内存优化Configures memory optimization for small aggregate data types | 标准版和高级版Standard and Premium |
set-max-intset-entriesset-max-intset-entries | 为较小的聚合数据类型配置 内存优化Configures memory optimization for small aggregate data types | 标准版和高级版Standard and Premium |
zset-max-ziplist-entrieszset-max-ziplist-entries | 为较小的聚合数据类型配置 内存优化Configures memory optimization for small aggregate data types | 标准版和高级版Standard and Premium |
zset-max-ziplist-valuezset-max-ziplist-value | 为较小的聚合数据类型配置 内存优化Configures memory optimization for small aggregate data types | 标准版和高级版Standard and Premium |
数据库databases | 配置数据库的数目。Configures the number of databases. 该属性只能在创建缓存时配置。This property can be configured only at cache creation. | 标准版和高级版Standard and Premium |
创建 Azure Redis 缓存To create an Azure Cache for Redis
可以使用 New-AzRedisCache cmdlet 创建新的 Azure Redis 缓存实例。New Azure Cache for Redis instances are created using the New-AzRedisCache cmdlet.
重要
第一次使用 Azure 门户在订阅中创建 Azure Redis 缓存时,门户将为该订阅注册 Microsoft.Cache
命名空间。The first time you create an Azure Cache for Redis in a subscription using the Azure portal, the portal registers the Microsoft.Cache
namespace for that subscription. 如果尝试使用 PowerShell 在订阅中创建第一个 Azure Redis 缓存,必须首先使用以下命令注册命名空间;否则,诸如 New-AzRedisCache
和 Get-AzRedisCache
的 cmdlet 会失败。If you attempt to create the first Azure Cache for Redis in a subscription using PowerShell, you must first register that namespace using the following command; otherwise cmdlets such as New-AzRedisCache
and Get-AzRedisCache
fail.
Register-AzResourceProvider -ProviderNamespace "Microsoft.Cache"
若要查看 New-AzRedisCache
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for New-AzRedisCache
, run the following command.
PS C:\> Get-Help New-AzRedisCache -detailed
NAME
New-AzRedisCache
SYNOPSIS
Creates a new Azure Cache for Redis.
SYNTAX
New-AzRedisCache -Name <String> -ResourceGroupName <String> -Location <String> [-RedisVersion <String>]
[-Size <String>] [-Sku <String>] [-MaxMemoryPolicy <String>] [-RedisConfiguration <Hashtable>] [-EnableNonSslPort
<Boolean>] [-ShardCount <Integer>] [-VirtualNetwork <String>] [-Subnet <String>] [-StaticIP <String>]
[<CommonParameters>]
DESCRIPTION
The New-AzRedisCache cmdlet creates a new Azure Cache for Redis.
PARAMETERS
-Name <String>
Name of the Azure Cache for Redis to create.
-ResourceGroupName <String>
Name of resource group in which to create the Azure Cache for Redis.
-Location <String>
Location in which to create the Azure Cache for Redis.
-RedisVersion <String>
RedisVersion is deprecated and will be removed in future release.
-Size <String>
Size of the Azure Cache for Redis. The default value is 1GB or C1. Possible values are P1, P2, P3, P4, C0, C1, C2, C3,
C4, C5, C6, 250MB, 1GB, 2.5GB, 6GB, 13GB, 26GB, 53GB.
-Sku <String>
Sku of Azure Cache for Redis. The default value is Standard. Possible values are Basic, Standard and Premium.
-MaxMemoryPolicy <String>
The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set
MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}
-RedisConfiguration <Hashtable>
All Redis Configuration Settings. Few possible keys: rdb-backup-enabled, rdb-storage-connection-string,
rdb-backup-frequency, maxmemory-reserved, maxmemory-policy, notify-keyspace-events, hash-max-ziplist-entries,
hash-max-ziplist-value, set-max-intset-entries, zset-max-ziplist-entries, zset-max-ziplist-value, databases.
-EnableNonSslPort <Boolean>
EnableNonSslPort is used by Azure Cache for Redis. If no value is provided, the default value is false and the
non-SSL port will be disabled. Possible values are true and false.
-ShardCount <Integer>
The number of shards to create on a Premium Cluster Cache.
-VirtualNetwork <String>
The exact ARM resource ID of the virtual network to deploy the Azure Cache for Redis in. Example format: /subscriptions/{
subid}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicNetwork/VirtualNetworks/{vnetName}
-Subnet <String>
Required when deploying an Azure Cache for Redis inside an existing Azure Virtual Network.
-StaticIP <String>
Required when deploying an Azure Cache for Redis inside an existing Azure Virtual Network.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
若要使用默认参数创建缓存,请运行以下命令。To create a cache with default parameters, run the following command.
New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "China North"
ResourceGroupName
、Name
和 Location
是必需的参数,其余则是可选参数并且有默认值。ResourceGroupName
, Name
, and Location
are required parameters, but the rest are optional and have default values. 运行前面的命令会使用指定的名称、位置和资源组创建标准 SKU Azure Redis 缓存实例,其大小为 1 GB,且禁用了非 SSL 端口。Running the previous command creates a Standard SKU Azure Cache for Redis instance with the specified name, location, and resource group, that is 1 GB in size with the non-SSL port disabled.
若要创建高级缓存,请指定大小 P1 (6 GB - 60 GB)、P2 (13 GB - 130 GB)、P3 (26 GB - 260 GB) 或 P4 (53 GB - 530 GB)。To create a premium cache, specify a size of P1 (6 GB - 60 GB), P2 (13 GB - 130 GB), P3 (26 GB - 260 GB), or P4 (53 GB - 530 GB). 若要启用群集,使用 ShardCount
参数指定分片计数。To enable clustering, specify a shard count using the ShardCount
parameter. 以下示例创建包含 3 个分片的 P1 高级缓存。The following example creates a P1 premium cache with 3 shards. P1 高级缓存的大小为 6 GB。由于我们指定了 3 个分片,因此总大小为 18 GB (3 x 6 GB)。A P1 premium cache is 6 GB in size, and since we specified three shards the total size is 18 GB (3 x 6 GB).
New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "China North" -Sku Premium -Size P1 -ShardCount 3
要指定 RedisConfiguration
参数的值,请以键/值对的方式将值括在 {}
内,例如 @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}
。To specify values for the RedisConfiguration
parameter, enclose the values inside {}
as key/value pairs like @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}
. 以下示例创建标准 1 GB 缓存,其包含 allkeys-random
maxmemory 策略,以及使用 KEA
配置的 keyspace 通知。The following example creates a standard 1 GB cache with allkeys-random
maxmemory policy and keyspace notifications configured with KEA
. 有关详细信息,请参阅密钥空间通知(高级设置)以及内存策略。For more information, see Keyspace notifications (advanced settings) and Memory policies.
New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "China North" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}
在缓存创建过程中配置数据库设置To configure the databases setting during cache creation
databases
设置只能在缓存创建过程中配置。The databases
setting can be configured only during cache creation. 下面的示例使用 New-AzRedisCache cmdlet 创建包含 48 个数据库的高级 P3 (26 GB) 缓存。The following example creates a premium P3 (26 GB) cache with 48 databases using the New-AzRedisCache cmdlet.
New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "China North" -Sku Premium -Size P3 -RedisConfiguration @{"databases" = "48"}
有关 databases
属性的详细信息,请参阅默认 Azure Redis 缓存服务器配置。For more information on the databases
property, see Default Azure Cache for Redis server configuration. 有关使用 New-AzRedisCache cmdlet 创建缓存的详细信息,请参阅前面的创建 Azure Redis 缓存部分。For more information on creating a cache using the New-AzRedisCache cmdlet, see the previous To create an Azure Cache for Redis section.
更新 Azure Redis 缓存To update an Azure Cache for Redis
可以使用 Set-AzRedisCache cmdlet 更新 Azure Redis 缓存实例。Azure Cache for Redis instances are updated using the Set-AzRedisCache cmdlet.
若要查看 Set-AzRedisCache
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for Set-AzRedisCache
, run the following command.
PS C:\> Get-Help Set-AzRedisCache -detailed
NAME
Set-AzRedisCache
SYNOPSIS
Set Azure Cache for Redis updatable parameters.
SYNTAX
Set-AzRedisCache -Name <String> -ResourceGroupName <String> [-Size <String>] [-Sku <String>]
[-MaxMemoryPolicy <String>] [-RedisConfiguration <Hashtable>] [-EnableNonSslPort <Boolean>] [-ShardCount
<Integer>] [<CommonParameters>]
DESCRIPTION
The Set-AzRedisCache cmdlet sets Azure Cache for Redis parameters.
PARAMETERS
-Name <String>
Name of the Azure Cache for Redis to update.
-ResourceGroupName <String>
Name of the resource group for the cache.
-Size <String>
Size of the Azure Cache for Redis. The default value is 1GB or C1. Possible values are P1, P2, P3, P4, C0, C1, C2, C3,
C4, C5, C6, 250MB, 1GB, 2.5GB, 6GB, 13GB, 26GB, 53GB.
-Sku <String>
Sku of Azure Cache for Redis. The default value is Standard. Possible values are Basic, Standard and Premium.
-MaxMemoryPolicy <String>
The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set
MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}
-RedisConfiguration <Hashtable>
All Redis Configuration Settings. Few possible keys: rdb-backup-enabled, rdb-storage-connection-string,
rdb-backup-frequency, maxmemory-reserved, maxmemory-policy, notify-keyspace-events, hash-max-ziplist-entries,
hash-max-ziplist-value, set-max-intset-entries, zset-max-ziplist-entries, zset-max-ziplist-value.
-EnableNonSslPort <Boolean>
EnableNonSslPort is used by Azure Cache for Redis. The default value is null and no change will be made to the
currently configured value. Possible values are true and false.
-ShardCount <Integer>
The number of shards to create on a Premium Cluster Cache.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
Set-AzRedisCache
cmdlet 可用于更新属性,例如 Size
、Sku
、EnableNonSslPort
和 RedisConfiguration
值。The Set-AzRedisCache
cmdlet can be used to update properties such as Size
, Sku
, EnableNonSslPort
, and the RedisConfiguration
values.
以下命令将更新名为 myCache 的 Azure Redis 缓存的 maxmemory-policy。The following command updates the maxmemory-policy for the Azure Cache for Redis named myCache.
Set-AzRedisCache -ResourceGroupName "myGroup" -Name "myCache" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random"}
缩放 Azure Redis 缓存To scale an Azure Cache for Redis
修改 Size
、Sku
或 ShardCount
属性时,可以使用 Set-AzRedisCache
来缩放 Azure Redis 缓存实例。Set-AzRedisCache
can be used to scale an Azure Cache for Redis instance when the Size
, Sku
, or ShardCount
properties are modified.
备注
使用 PowerShell 缩放缓存受到的限制和要遵循的准则与在 Azure 门户中缩放缓存相同。Scaling a cache using PowerShell is subject to the same limits and guidelines as scaling a cache from the Azure portal. 可以扩展到不同定价层,但有以下限制。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. 必须在一个缩放操作中从 基本 缩放到 标准 ,并在后续的缩放操作中从 标准 缩放到 高级 。You must 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.
有关详细信息,请参阅如何缩放 Azure Redis 缓存。For more information, see How to Scale Azure Cache for Redis.
以下示例演示了如何将名为 myCache
的缓存缩放为 2.5 GB 缓存。The following example shows how to scale a cache named myCache
to a 2.5 GB cache. 请注意,此命令适用于基本或标准缓存。Note that this command works for both a Basic or a Standard cache.
Set-AzRedisCache -ResourceGroupName myGroup -Name myCache -Size 2.5GB
发出此命令之后,会返回缓存的状态(类似于调用 Get-AzRedisCache
)。After this command is issued, the status of the cache is returned (similar to calling Get-AzRedisCache
). 请注意,ProvisioningState
为 Scaling
。Note that the ProvisioningState
is Scaling
.
PS C:\> Set-AzRedisCache -Name myCache -ResourceGroupName myGroup -Size 2.5GB
Name : mycache
Id : /subscriptions/12ad12bd-abdc-2231-a2ed-a2b8b246bbad4/resourceGroups/mygroup/providers/Mi
crosoft.Cache/Redis/mycache
Location : China North
Type : Microsoft.Cache/Redis
HostName : mycache.redis.cache.chinacloudapi.cn
Port : 6379
ProvisioningState : Scaling
SslPort : 6380
RedisConfiguration : {[maxmemory-policy, volatile-lru], [maxmemory-reserved, 150], [notify-keyspace-events, KEA],
[maxmemory-delta, 150]...}
EnableNonSslPort : False
RedisVersion : 3.0
Size : 1GB
Sku : Standard
ResourceGroupName : mygroup
PrimaryKey : ....
SecondaryKey : ....
VirtualNetwork :
Subnet :
StaticIP :
TenantSettings : {}
ShardCount :
缩放操作完成后,ProvisioningState
更改为 Succeeded
。When the scaling operation is complete, the ProvisioningState
changes to Succeeded
. 如果需要进行后续的缩放操作,例如先从基本缓存更改为标准缓存,再更改大小,则必须等到前面操作完成,否则会收到类似于下面的错误。If you need to make a subsequent scaling operation, such as changing from Basic to Standard and then changing the size, you must wait until the previous operation is complete or you receive an error similar to the following.
Set-AzRedisCache : Conflict: The resource '...' is not in a stable state, and is currently unable to accept the update request.
获取有关 Azure Redis 缓存的信息To get information about an Azure Cache for Redis
可以使用 Get-AzRedisCache cmdlet 检索有关缓存的信息。You can retrieve information about a cache using the Get-AzRedisCache cmdlet.
若要查看 Get-AzRedisCache
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for Get-AzRedisCache
, run the following command.
PS C:\> Get-Help Get-AzRedisCache -detailed
NAME
Get-AzRedisCache
SYNOPSIS
Gets details about a single cache or all caches in the specified resource group or all caches in the current
subscription.
SYNTAX
Get-AzRedisCache [-Name <String>] [-ResourceGroupName <String>] [<CommonParameters>]
DESCRIPTION
The Get-AzRedisCache cmdlet gets the details about a cache or caches depending on input parameters. If both
ResourceGroupName and Name parameters are provided then Get-AzRedisCache will return details about the
specific cache name provided.
If only ResourceGroupName is provided than it will return details about all caches in the specified resource group.
If no parameters are given than it will return details about all caches the current subscription.
PARAMETERS
-Name <String>
The name of the cache. When this parameter is provided along with ResourceGroupName, Get-AzRedisCache
returns the details for the cache.
-ResourceGroupName <String>
The name of the resource group that contains the cache or caches. If ResourceGroupName is provided with Name
then Get-AzRedisCache returns the details of the cache specified by Name. If only the ResourceGroup
parameter is provided, then details for all caches in the resource group are returned.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
若要返回当前订阅中所有缓存的相关信息,请运行不带任何参数的 Get-AzRedisCache
。To return information about all caches in the current subscription, run Get-AzRedisCache
without any parameters.
Get-AzRedisCache
若要返回特定资源组中所有缓存的相关信息,请结合 ResourceGroupName
参数运行 Get-AzRedisCache
。To return information about all caches in a specific resource group, run Get-AzRedisCache
with the ResourceGroupName
parameter.
Get-AzRedisCache -ResourceGroupName myGroup
若要返回特定缓存的相关信息,请运行 Get-AzRedisCache
,并使用包含缓存名称的 Name
参数,和包含该缓存所在资源组的 ResourceGroupName
参数。To return information about a specific cache, run Get-AzRedisCache
with the Name
parameter containing the name of the cache, and the ResourceGroupName
parameter with the resource group containing that cache.
PS C:\> Get-AzRedisCache -Name myCache -ResourceGroupName myGroup
Name : mycache
Id : /subscriptions/12ad12bd-abdc-2231-a2ed-a2b8b246bbad4/resourceGroups/myGroup/providers/Mi
crosoft.Cache/Redis/mycache
Location : China North
Type : Microsoft.Cache/Redis
HostName : mycache.redis.cache.chinacloudapi.cn
Port : 6379
ProvisioningState : Succeeded
SslPort : 6380
RedisConfiguration : {[maxmemory-policy, volatile-lru], [maxmemory-reserved, 62], [notify-keyspace-events, KEA],
[maxclients, 1000]...}
EnableNonSslPort : False
RedisVersion : 3.0
Size : 1GB
Sku : Standard
ResourceGroupName : myGroup
VirtualNetwork :
Subnet :
StaticIP :
TenantSettings : {}
ShardCount :
检索 Azure Redis 缓存的访问密钥To retrieve the access keys for an Azure Cache for Redis
若要检索缓存的访问密钥,可以使用 Get-AzRedisCacheKey cmdlet。To retrieve the access keys for your cache, you can use the Get-AzRedisCacheKey cmdlet.
若要查看 Get-AzRedisCacheKey
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for Get-AzRedisCacheKey
, run the following command.
PS C:\> Get-Help Get-AzRedisCacheKey -detailed
NAME
Get-AzRedisCacheKey
SYNOPSIS
Gets the accesskeys for the specified Azure Cache for Redis.
SYNTAX
Get-AzRedisCacheKey -Name <String> -ResourceGroupName <String> [<CommonParameters>]
DESCRIPTION
The Get-AzRedisCacheKey cmdlet gets the access keys for the specified cache.
PARAMETERS
-Name <String>
Name of the Azure Cache for Redis.
-ResourceGroupName <String>
Name of the resource group for the cache.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
若要检索缓存的密钥,请调用 Get-AzRedisCacheKey
cmdlet,并传递缓存的名称以及包含该缓存的资源组的名称。To retrieve the keys for your cache, call the Get-AzRedisCacheKey
cmdlet and pass in the name of your cache the name of the resource group that contains the cache.
PS C:\> Get-AzRedisCacheKey -Name myCache -ResourceGroupName myGroup
PrimaryKey : b2wdt43sfetlju4hfbryfnregrd9wgIcc6IA3zAO1lY=
SecondaryKey : ABhfB757JgjIgt785JgKH9865eifmekfnn649303JKL=
生成 Azure Redis 缓存的访问密钥To regenerate access keys for your Azure Cache for Redis
若要重新生成缓存的访问密钥,可以使用 New-AzRedisCacheKey cmdlet。To regenerate the access keys for your cache, you can use the New-AzRedisCacheKey cmdlet.
若要查看 New-AzRedisCacheKey
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for New-AzRedisCacheKey
, run the following command.
PS C:\> Get-Help New-AzRedisCacheKey -detailed
NAME
New-AzRedisCacheKey
SYNOPSIS
Regenerates the access key of an Azure Cache for Redis.
SYNTAX
New-AzRedisCacheKey -Name <String> -ResourceGroupName <String> -KeyType <String> [-Force] [<CommonParameters>]
DESCRIPTION
The New-AzRedisCacheKey cmdlet regenerate the access key of an Azure Cache for Redis.
PARAMETERS
-Name <String>
Name of the Azure Cache for Redis.
-ResourceGroupName <String>
Name of the resource group for the cache.
-KeyType <String>
Specifies whether to regenerate the primary or secondary access key. Possible values are Primary or Secondary.
-Force
When the Force parameter is provided, the specified access key is regenerated without any confirmation prompts.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
若要重新生成缓存的主要或辅助密钥,请调用 New-AzRedisCacheKey
cmdlet,传入名称和资源组,并为 KeyType
参数指定 Primary
或 Secondary
。To regenerate the primary or secondary key for your cache, call the New-AzRedisCacheKey
cmdlet and pass in the name, resource group, and specify either Primary
or Secondary
for the KeyType
parameter. 以下示例重新生成缓存的辅助访问密钥。In the following example, the secondary access key for a cache is regenerated.
PS C:\> New-AzRedisCacheKey -Name myCache -ResourceGroupName myGroup -KeyType Secondary
Confirm
Are you sure you want to regenerate Secondary key for Azure Cache for Redis 'myCache'?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
PrimaryKey : b2wdt43sfetlju4hfbryfnregrd9wgIcc6IA3zAO1lY=
SecondaryKey : c53hj3kh4jhHjPJk8l0jji785JgKH9865eifmekfnn6=
删除 Azure Redis 缓存To delete an Azure Cache for Redis
若要删除 Azure Redis 缓存,请使用 Remove-AzRedisCache cmdlet。To delete an Azure Cache for Redis, use the Remove-AzRedisCache cmdlet.
若要查看 Remove-AzRedisCache
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for Remove-AzRedisCache
, run the following command.
PS C:\> Get-Help Remove-AzRedisCache -detailed
NAME
Remove-AzRedisCache
SYNOPSIS
Remove Azure Cache for Redis if exists.
SYNTAX
Remove-AzRedisCache -Name <String> -ResourceGroupName <String> [-Force] [-PassThru] [<CommonParameters>
DESCRIPTION
The Remove-AzRedisCache cmdlet removes an Azure Cache for Redis if it exists.
PARAMETERS
-Name <String>
Name of the Azure Cache for Redis to remove.
-ResourceGroupName <String>
Name of the resource group of the cache to remove.
-Force
When the Force parameter is provided, the cache is removed without any confirmation prompts.
-PassThru
By default Remove-AzRedisCache removes the cache and does not return any value. If the PassThru par
is provided then Remove-AzRedisCache returns a boolean value indicating the success of the operatio
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
以下示例删除名为 myCache
的缓存。In the following example, the cache named myCache
is removed.
PS C:\> Remove-AzRedisCache -Name myCache -ResourceGroupName myGroup
Confirm
Are you sure you want to remove Azure Cache for Redis 'myCache'?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
导入 Azure Redis 缓存To import an Azure Cache for Redis
可以使用 Import-AzRedisCache
cmdlet 将数据导入 Azure Redis 缓存实例。You can import data into an Azure Cache for Redis instance using the Import-AzRedisCache
cmdlet.
重要
导入/导出仅适用于高级层缓存。Import/Export is only available for Premium tier caches. 有关导入/导出的详细信息,请参阅在 Azure Redis 缓存中导入和导出数据。For more information about Import/Export, see Import and Export data in Azure Cache for Redis.
若要查看 Import-AzRedisCache
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for Import-AzRedisCache
, run the following command.
PS C:\> Get-Help Import-AzRedisCache -detailed
NAME
Import-AzRedisCache
SYNOPSIS
Import data from blobs to Azure Cache for Redis.
SYNTAX
Import-AzRedisCache -Name <String> -ResourceGroupName <String> -Files <String[]> [-Format <String>] [-Force]
[-PassThru] [<CommonParameters>]
DESCRIPTION
The Import-AzRedisCache cmdlet imports data from the specified blobs into Azure Cache for Redis.
PARAMETERS
-Name <String>
The name of the cache.
-ResourceGroupName <String>
The name of the resource group that contains the cache.
-Files <String[]>
SAS urls of blobs whose content should be imported into the cache.
-Format <String>
Format for the blob. Currently "rdb" is the only supported, with other formats expected in the future.
-Force
When the Force parameter is provided, import will be performed without any confirmation prompts.
-PassThru
By default Import-AzRedisCache imports data in cache and does not return any value. If the PassThru
parameter is provided then Import-AzRedisCache returns a boolean value indicating the success of the
operation.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
以下命令将数据从 SAS URI 所指定的 Blob 导入 Azure Redis 缓存中。The following command imports data from the blob specified by the SAS uri into Azure Cache for Redis.
PS C:\>Import-AzRedisCache -ResourceGroupName "resourceGroupName" -Name "cacheName" -Files @("https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainername/blobname?sv=2015-04-05&sr=b&sig=caIwutG2uDa0NZ8mjdNJdgOY8%2F8mhwRuGNdICU%2B0pI4%3D&st=2016-05-27T00%3A00%3A00Z&se=2016-05-28T00%3A00%3A00Z&sp=rwd") -Force
导出 Azure Redis 缓存To export an Azure Cache for Redis
可以使用 Export-AzRedisCache
cmdlet 将数据从 Azure Redis 缓存实例导出。You can export data from an Azure Cache for Redis instance using the Export-AzRedisCache
cmdlet.
重要
导入/导出仅适用于高级层缓存。Import/Export is only available for Premium tier caches. 有关导入/导出的详细信息,请参阅在 Azure Redis 缓存中导入和导出数据。For more information about Import/Export, see Import and Export data in Azure Cache for Redis.
若要查看 Export-AzRedisCache
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for Export-AzRedisCache
, run the following command.
PS C:\> Get-Help Export-AzRedisCache -detailed
NAME
Export-AzRedisCache
SYNOPSIS
Exports data from Azure Cache for Redis to a specified container.
SYNTAX
Export-AzRedisCache -Name <String> -ResourceGroupName <String> -Prefix <String> -Container <String> [-Format
<String>] [-PassThru] [<CommonParameters>]
DESCRIPTION
The Export-AzRedisCache cmdlet exports data from Azure Cache for Redis to a specified container.
PARAMETERS
-Name <String>
The name of the cache.
-ResourceGroupName <String>
The name of the resource group that contains the cache.
-Prefix <String>
Prefix to use for blob names.
-Container <String>
SAS url of container where data should be exported.
-Format <String>
Format for the blob. Currently "rdb" is the only supported, with other formats expected in the future.
-PassThru
By default Export-AzRedisCache does not return any value. If the PassThru parameter is provided
then Export-AzRedisCache returns a boolean value indicating the success of the operation.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
以下命令将数据从 Azure Redis 缓存实例导出到 SAS URI 所指定的容器中。The following command exports data from an Azure Cache for Redis instance into the container specified by the SAS uri.
PS C:\>Export-AzRedisCache -ResourceGroupName "resourceGroupName" -Name "cacheName" -Prefix "blobprefix"
-Container "https://mystorageaccount.blob.core.chinacloudapi.cn/mycontainer?sv=2015-04-05&sr=c&sig=HezZtBZ3DURmEGDduauE7
pvETY4kqlPI8JCNa8ATmaw%3D&st=2016-05-27T00%3A00%3A00Z&se=2016-05-28T00%3A00%3A00Z&sp=rwdl"
重启 Azure Redis 缓存To reboot an Azure Cache for Redis
可以使用 Reset-AzRedisCache
cmdlet 重启 Azure Redis 缓存实例。You can reboot your Azure Cache for Redis instance using the Reset-AzRedisCache
cmdlet.
重要
重启仅适用于高级层缓存。Reboot is only available for Premium tier caches. 有关如何重启缓存的详细信息,请参阅缓存管理 - 重启。For more information about rebooting your cache, see Cache administration - reboot.
若要查看 Reset-AzRedisCache
的可用参数列表及其说明,请运行以下命令。To see a list of available parameters and their descriptions for Reset-AzRedisCache
, run the following command.
PS C:\> Get-Help Reset-AzRedisCache -detailed
NAME
Reset-AzRedisCache
SYNOPSIS
Reboot specified node(s) of an Azure Cache for Redis instance.
SYNTAX
Reset-AzRedisCache -Name <String> -ResourceGroupName <String> -RebootType <String> [-ShardId <Integer>]
[-Force] [-PassThru] [<CommonParameters>]
DESCRIPTION
The Reset-AzRedisCache cmdlet reboots the specified node(s) of an Azure Cache for Redis instance.
PARAMETERS
-Name <String>
The name of the cache.
-ResourceGroupName <String>
The name of the resource group that contains the cache.
-RebootType <String>
Which node to reboot. Possible values are "PrimaryNode", "SecondaryNode", "AllNodes".
-ShardId <Integer>
Which shard to reboot when rebooting a premium cache with clustering enabled.
-Force
When the Force parameter is provided, reset will be performed without any confirmation prompts.
-PassThru
By default Reset-AzRedisCache does not return any value. If the PassThru parameter is provided
then Reset-AzRedisCache returns a boolean value indicating the success of the operation.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
以下命令重新启动指定缓存的两个节点。The following command reboots both nodes of the specified cache.
PS C:\>Reset-AzRedisCache -ResourceGroupName "resourceGroupName" -Name "cacheName" -RebootType "AllNodes"
-Force
后续步骤Next steps
要了解有关将 Windows PowerShell 与 Azure 配合使用的详细信息,请参阅以下资源:To learn more about using Windows PowerShell with Azure, see the following resources:
- MSDN 上的 Azure Redis 缓存 cmdlet 文档Azure Cache for Redis cmdlet documentation on MSDN
- Azure Resource Manager Cmdlet:了解如何在 Azure Resource Manager 模块中使用这些 cmdlet。Azure Resource Manager Cmdlets: Learn to use the cmdlets in the Azure Resource Manager module.
- 使用资源组管理 Azure 资源:了解如何在 Azure 门户中创建和管理资源组。Using Resource groups to manage your Azure resources: Learn how to create and manage resource groups in the Azure portal.
- Azure 博客:了解 Azure 中的新功能。Azure blog: Learn about new features in Azure.
- Windows PowerShell 博客:了解 Windows PowerShell 中的新功能。Windows PowerShell blog: Learn about new features in Windows PowerShell.
- “你好,脚本专家!”博客:从 Windows PowerShell 社区获取实用提示和技巧。"Hey, Scripting Guy!" Blog: Get real-world tips and tricks from the Windows PowerShell community.