Compartir a través de

使用 Azure PowerShell 管理 Azure Redis

  • [PowerShell]/azure-cache-for-redis/cache-how-to-manage-redis-cache-powershell.md)
  • [Azure CLI]/azure-cache-for-redis/cache-manage-cli.md)

Azure 托管 Redis

  1. 若要创建 Azure 托管 Redis(预览版)实例,请登录到 Azure 门户并选择“创建资源”。

  2. 在“新建”页面上的搜索框中键入“Azure Cache for Redis”。

  3. 在“新建 Redis 缓存”页上配置新缓存的设置。

    设置 选择值 DESCRIPTION
    订阅 单击下拉箭头并选择你的订阅。 创建新的 Azure 托管 Redis 实例所需的订阅。
    资源组 单击下拉箭头并选择一个资源组,或者选择新建并输入新的资源组名称。 要在其中创建缓存和其他资源的资源组的名称。 将所有应用资源放入一个资源组可以轻松地统一管理或删除这些资源。
    DNS 名称 输入在区域中唯一的名称。 如果与缓存的区域名称组合,缓存名称必须为介于 1 到 63 个字符的字符串,且只能包含数字、字母或连字符。 (如果缓存名称长度少于 45 个字符,则它应该可以在所有当前可用的区域中正常工作。)该名称必须以数字或字母开头和结尾,且不能包含连续的连字符。 缓存实例的主机名\<DNS name\>.\<Azure region\>.redis.chinacloudapi.cn
    位置 下拉并选择一个位置。 Azure 托管 Redis 在选定的 Azure 区域中可用。
    缓存类型 下拉列表并选择性能层和缓存大小。 层级确定了 Redis 实例的性能,而缓存大小确定可用于存储数据的内存。 有关选择适当的性能层的指导,请参阅选择适当层级

    显示 Azure 托管 Redis“基本信息”选项卡的屏幕截图。

  4. 选择“下一步: 网络”,并选择公共或专用终结点。

  5. 选择“下一页: 高级”。

    配置要添加到实例的任何 Redis 模块

    默认情况下,对于新的托管缓存:

    • 已启用 Microsoft Entra ID。
    • 出于安全原因,“访问密钥身份验证”处于禁用状态

    重要

    为了获得最佳安全性,我们建议你在可能的情况下使用 Microsoft Entra ID 和托管标识来授权针对缓存的请求。 与共享访问密钥授权相比,使用 Microsoft Entra ID 和托管标识进行授权提供了更高的安全性和易用性。 若要详细了解如何将托管标识与缓存配合使用,请参阅使用 Microsoft Entra ID 进行缓存身份验证

    集群策略设置为企业(用于非集群缓存),或设置为 OSS(用于集群缓存)。 有关选择“群集策略”的详细信息,请参阅群集策略

    屏幕截图显示 Azure 托管 Redis 的“高级”选项卡。

    如果使用活动异地复制,则必须在创建过程中对其进行配置。 有关详细信息,请参阅为 Azure 托管 Redis 实例配置活动异地复制

    重要

    创建 Azure 托管 Redis(预览版)实例后,无法更改群集策略。 如果使用 RediSearch,则需要企业群集策略,NoEviction 是唯一支持的逐出策略。

    重要

    如果在异地复制组中使用此缓存实例,则创建实例后无法更改逐出策略。 在创建缓存之前,请务必了解主节点的逐出策略。 有关活动异地复制的详细信息,请参阅活动异地复制先决条件

    重要

    创建缓存实例后,无法更改模块。 必须在创建 Azure Cache for Redis 实例时启用模块。 没有在创建缓存后启用模块配置的选项。

  6. 选择下一步:标记并跳过。

  7. 选择 “下一步:查看 + 创建”。

  8. 检查设置,然后选择“创建”。

    创建 Redis 实例需要几分钟时间。 可以在 Azure 托管 Redis 的“概述”页面上监视进度。 如果状态显示为正在运行,则表示该缓存可供使用。

适用于 Redis 的 Azure 缓存

  1. 若要创建缓存,请登录到 Azure 门户并选择“创建资源”

    左侧导航窗格中突出显示了“创建资源”。

  2. 入门页的搜索框中输入Azure Cache for Redis。 然后选择创建

    Azure 市场的屏幕截图,其中搜索框中显示“Azure Cache for Redis”,并用红色框突出显示了“创建”按钮。

  3. 在“新建 Redis 缓存”页上配置缓存的设置。

    设置 选择值 DESCRIPTION
    订阅 单击下拉箭头并选择你的订阅。 要在其下创建此新的 Azure Cache for Redis 实例的订阅。
    资源组 单击下拉箭头并选择一个资源组,或者选择新建并输入新的资源组名称。 要在其中创建缓存和其他资源的资源组的名称。 将所有应用资源放入一个资源组可以轻松地统一管理或删除这些资源。
    DNS 名称 输入唯一名称。 缓存名称必须是包含 1 到 63 个字符的字符串,只能包含数字、字母或连字符。 该名称必须以数字或字母开头和结尾,且不能包含连续的连字符。 缓存实例的主机名<DNS name>.redis.cache.chinacloudapi.cn
    位置 下拉并选择一个位置。 选择靠近使用缓存的其他服务的区域
    缓存 SKU 下拉并选择一个 SKU 此 SKU 决定可用于缓存的大小、性能和功能参数。 有关详细信息,请参阅用于 Redis 的 Azure 缓存概述
    缓存大小 打开下拉列表并选择缓存的大小 有关详细信息,请参阅用于 Redis 的 Azure 缓存概述
  4. 选择网络选项卡,或选择网络按钮(位于页面底部) 。

  5. 网络选项卡中,选择你的连接方式。

  6. 选择“下一步: 高级”选项卡,或在页面底部选择“下一步: 高级”按钮,以查看“高级”选项卡。

    显示工作窗格中的“高级”选项卡和可供选择选项的屏幕截图。

    • 对于“基本”或“标准”缓存,请切换非 TLS 端口的选项。 还可以选择是否要启用“Microsoft Entra 身份验证”。
    • 对于“高级”缓存,请配置非 TLS 端口、群集、托管标识和数据持久性的设置。 还可以选择是否要启用“Microsoft Entra 身份验证”。
  7. 选择下一步: 标签选项卡,或选择页面底部的下一步: 标签按钮。

  8. 如果希望对资源进行分类,可选择地在标签选项卡中输入名称和值。

  9. 选择“查看 + 创建”。 随后你会转到“查看 + 创建”选项卡,Azure 将在此处验证配置。

  10. 显示绿色的“已通过验证”消息后,选择创建

创建缓存需要一段时间。 可以在 Azure Cache for Redis 的概述页上监视进度。 如果状态显示为正在运行,则表示该缓存可供使用。

本文介绍如何执行创建、更新和缩放 Azure Redis 实例。

注释

Azure 提供两种不同的部署模型用于创建和处理资源:Azure 资源管理器模型和经典模型。 本文介绍了资源管理器部署模型的使用。 对于新部署,建议使用资源管理器部署模型而非经典部署模型。

有关经典部署模型的详细信息,请参阅 Azure 资源管理器与经典部署:了解部署模型和资源状态

先决条件

如果已安装 Azure PowerShell,则必须确保安装的是 Azure PowerShell 版本 12.4.0 或更高版本。 可在 Azure PowerShell 命令提示符处使用以下命令查看 Azure PowerShell 版本。

    Get-Module Az | format-table version

首先,必须使用以下命令登录到 Azure。

    Connect-AzAccount -Environment AzureChinaCloud

在 Azure 登录对话框中指定 Azure 帐户的电子邮件地址和密码。

接下来,如果有多个 Azure 订阅,则需要设置 Azure 订阅。 若要查看当前订阅的列表,请运行以下命令。

    Get-AzSubscription | sort SubscriptionName | Select SubscriptionName

若要指定订阅,请运行以下命令。 在以下示例中,订阅名为 ContosoSubscription

    Select-AzSubscription -SubscriptionName ContosoSubscription

在可以将 Windows PowerShell 与 Azure 资源管理器一起使用之前,需验证你的设置:

  • Windows PowerShell 3.0 版或 4.0 版。 若要查找 Windows PowerShell 的版本,请键入:$PSVersionTable 并验证 PSVersion 的值是否为 3.0 或 4.0。 若要安装兼容版本,请参阅 Windows Management Framework 3.0

要获取你在本教程中看到的任何 cmdlet 的详细帮助信息,请使用 Get-Help cmdlet。

    Get-Help <cmdlet-name> -Detailed

如何连接到其他云

默认情况下,Azure 环境是 AzureCloud,它表示全局 Azure 云实例。 若要连接到其他实例,请结合使用 Connect-AzAccount-Environment 或结合使用 -EnvironmentName 命令行开关与所需环境或环境名称。

若要查看可用环境列表,请运行 Get-AzEnvironment cmdlet。

连接到由世纪互联运营的 Microsoft Azure

若要连接到由世纪互联运营的 Microsoft Azure,请使用以下命令之一。

    Connect-AzAccount -EnvironmentName AzureChinaCloud

    Connect-AzAccount -Environment (Get-AzEnvironment -Name AzureChinaCloud)

若要在由世纪互联云运营的 Microsoft Azure 中创建缓存,请使用以下位置之一。

  • 中国东部
  • 中国北部

Azure 托管的 Redis PowerShell 参数和属性

有关所有 Azure 托管 Redis PowerShell 参数和属性的列表,请参阅 New-AzRedisEnterpriseCache

创建 Azure 托管的 Redis

可以使用 New-AzRedisEnterpriseCache cmdlet 创建新的 Azure 托管 Redis 实例。

重要

第一次使用 Azure 门户在订阅中创建 Azure 托管 Redis 时,门户将为该订阅注册 Microsoft.Cache 命名空间。 如果尝试使用 PowerShell 在订阅中创建第一个 Azure 托管 Redis,必须首先使用以下命令注册命名空间;否则,诸如 New-AzRedisEnterpriseCacheGet-AzRedisEnterpriseCache 的 cmdlet 会失败。

Register-AzResourceProvider -ProviderNamespace "Microsoft.Cache"

若要查看 New-AzRedisEnterpriseCache的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help New-AzRedisEnterpriseCache -detailed

    NAME
        New-AzRedisEnterpriseCache

    SYNOPSIS
        Creates a new Azure Managed Redis.


    SYNTAX
        New-AzRedisEnterpriseCache -Name <String> -ResourceGroupName <String> -Location <String> [-RedisVersion <String>]
        [-Sku <String>] [-MaxMemoryPolicy <String>] [-RedisConfiguration <Hashtable>] [-EnableNonSslPort
        <Boolean>] [-ShardCount <Integer>] [-VirtualNetwork <String>] [-Subnet <String>] [-StaticIP <String>]
        [<CommonParameters>]


    DESCRIPTION
        The New-AzRedisEnterpriseCache cmdlet creates a new Azure Managed Redis.


    PARAMETERS
        -Name <String>
            Name of the Azure Managed Redis to create.

        -ResourceGroupName <String>
            Name of resource group in which to create the Azure Managed Redis.

        -Location <String>
            Location in which to create the Azure Managed Redis.

        -RedisVersion <String>
            RedisVersion is deprecated and will be removed in future release.

        -Sku <String>
            Sku of Azure Managed Redis.

        -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 Managed 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 Cluster Cache.

        -VirtualNetwork <String>
            The exact ARM resource ID of the virtual network to deploy the Azure Managed Redis in. Example format: /subscriptions/{
            subid}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicNetwork/VirtualNetworks/{vnetName}

        -Subnet <String>
            Required when deploying an Azure Managed Redis inside an existing Azure Virtual Network.

        -StaticIP <String>
            Required when deploying an Azure Managed 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).

若要使用默认参数创建缓存,请运行以下命令。

    New-AzRedisEnterpriseCache -ResourceGroupName myGroup -Name mycache -Location "China North"

ResourceGroupNameNameLocation 是必需的参数,其余则是可选参数并且有默认值。 运行前面的命令会使用指定的名称、位置和资源组创建 Azure 托管 Redis 实例。 实例的大小为 1 GB,且禁用了非 SSL 端口。

若要启用群集,使用 ShardCount 参数指定分片计数。

要指定 RedisConfiguration 参数的值,请以键/值对的方式将值括在 {} 内,例如 @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}。 以下示例将创建 1 GB 缓存,其包含 allkeys-random maxmemory 策略,以及使用 KEA 配置的 keyspace 通知。 有关详细信息,请参阅 [密钥空间通知(高级设置)]/azure-cache-for-redis/cache-configure.md#keyspace-notifications-advanced-settings)和[内存策略]/azure-cache-for-redis/cache-configure.md#memory-policies)。

    New-AzRedisEnterpriseCache -ResourceGroupName myGroup -Name mycache -Location "China North" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}

在缓存创建过程中配置数据库设置

databases 设置只能在缓存创建过程中配置。 下面的示例使用 New-AzRedisEnterpriseCache cmdlet 创建包含 48 个数据库的缓存。

    New-AzRedisEnterpriseCache -ResourceGroupName myGroup -Name mycache -Location "China North" -Sku B1 -RedisConfiguration @{"databases" = "48"}

有关 databases 属性的详细信息,请参阅 [默认 Azure 托管的 Redis 服务器配置]/azure-cache-for-redis/cache-configure.md#default-redis-server-configuration)。 有关使用 New-AzRedisEnterpriseCache cmdlet 创建缓存的详细信息,请参阅前面的“创建 Azure 托管 Redis”部分。

更新 Azure 托管的 Redis

可以使用 [Set-AzRedisEnterpriseCache] cmdlet 更新 Azure 托管 Redis 实例。

若要查看 Set-AzRedisEnterpriseCache的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help Set-AzRedisEnterpriseCache -detailed

    NAME
        Set-AzRedisEnterpriseCache

    SYNOPSIS
        Set Azure Managed Redis updatable parameters.

    SYNTAX
        Set-AzRedisEnterpriseCache -Name <String> -ResourceGroupName <String> [-Sku <String>]
        [-MaxMemoryPolicy <String>] [-RedisConfiguration <Hashtable>] [-EnableNonSslPort <Boolean>] [-ShardCount
        <Integer>] [<CommonParameters>]

    DESCRIPTION
        The Set-AzRedisEnterpriseCache cmdlet sets Azure Managed Redis parameters.

    PARAMETERS
        -Name <String>
            Name of the Azure Managed Redis to update.

        -ResourceGroupName <String>
            Name of the resource group for the cache.

        -Sku <String>
            Sku of Azure Managed Redis.

        -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 Managed 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 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-AzRedisEnterpriseCache cmdlet 可用于更新属性,例如 SkuEnableNonSslPortRedisConfiguration 值。

以下命令将更新名为 myCache 的 Azure 托管的 Redis 的 maxmemory-policy。

    Set-AzRedisEnterpriseCache -ResourceGroupName "myGroup" -Name "myCache" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random"}

获取有关 Azure 托管 Redis 的信息

可以使用 Get-AzRedisEnterpriseCache cmdlet 检索有关缓存的信息。

若要查看 Get-AzRedisEnterpriseCache的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help Get-AzRedisEnterpriseCache -detailed

    NAME
        Get-AzRedisEnterpriseCache

    SYNOPSIS
        Gets details about a single cache or all caches in the specified resource group or all caches in the current
        subscription.

    SYNTAX
        Get-AzRedisEnterpriseCache [-Name <String>] [-ResourceGroupName <String>] [<CommonParameters>]

    DESCRIPTION
        The Get-AzRedisEnterpriseCache cmdlet gets the details about a cache or caches depending on input parameters. If both
        ResourceGroupName and Name parameters are provided then Get-AzRedisEnterpriseCache 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-AzRedisEnterpriseCache
            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-AzRedisEnterpriseCache 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-AzRedisEnterpriseCache

    Get-AzRedisEnterpriseCache

若要返回特定资源组中所有缓存的相关信息,请结合 Get-AzRedisEnterpriseCache 参数运行 ResourceGroupName

    Get-AzRedisEnterpriseCache -ResourceGroupName myGroup

若要返回特定缓存的相关信息,请运行 Get-AzRedisEnterpriseCache,并使用包含缓存名称的 Name 参数,和包含该缓存所在资源组的 ResourceGroupName 参数。

    PS C:\> Get-AzRedisEnterpriseCache -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               : 10000
    ProvisioningState  : Succeeded
    SslPort            : 6380
    RedisConfiguration : {[maxmemory-policy, volatile-lru], [maxmemory-reserved, 62], [notify-keyspace-events, KEA],
                         [maxclients, 1000]...}
    EnableNonSslPort   : False
    RedisVersion       : 3.0
    Sku                : B1
    ResourceGroupName  : myGroup
    VirtualNetwork     :
    Subnet             :
    StaticIP           :
    TenantSettings     : {}
    ShardCount         :

获取 Azure 托管版 Redis 的访问密钥

若要检索缓存的访问密钥,可以使用 Get-AzRedisEnterpriseCacheKey cmdlet。

若要查看 Get-AzRedisEnterpriseCacheKey的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help Get-AzRedisEnterpriseCacheKey -detailed

    NAME
        Get-AzRedisEnterpriseCacheKey

    SYNOPSIS
        Gets the accesskeys for the specified Azure Managed Redis.


    SYNTAX
        Get-AzRedisEnterpriseCacheKey -Name <String> -ResourceGroupName <String> [<CommonParameters>]

    DESCRIPTION
        The Get-AzRedisEnterpriseCacheKey cmdlet gets the access keys for the specified cache.

    PARAMETERS
        -Name <String>
            Name of the Azure Managed 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-AzRedisEnterpriseCacheKey cmdlet,并传递缓存的名称以及包含该缓存的资源组的名称。

    PS C:\> Get-AzRedisEnterpriseCacheKey -Name myCache -ResourceGroupName myGroup

    PrimaryKey   : b2wdt43sfetlju4hfbryfnregrd9wgIcc6IA3zAO1lY=
    SecondaryKey : ABhfB757JgjIgt785JgKH9865eifmekfnn649303JKL=

重新生成 Azure 托管 Redis 的访问密钥

若要重新生成缓存的访问密钥,可以使用 New-AzRedisEnterpriseCacheKey cmdlet。

若要查看 New-AzRedisEnterpriseCacheKey的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help New-AzRedisEnterpriseCacheKey -detailed

    NAME
        New-AzRedisEnterpriseCacheKey

    SYNOPSIS
        Regenerates the access key of an Azure Managed Redis.

    SYNTAX
        New-AzRedisEnterpriseCacheKey -Name <String> -ResourceGroupName <String> -KeyType <String> [-Force] [<CommonParameters>]

    DESCRIPTION
        The New-AzRedisEnterpriseCacheKey cmdlet regenerate the access key of an Azure Managed Redis.

    PARAMETERS
        -Name <String>
            Name of the Azure Managed 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-AzRedisEnterpriseCacheKey cmdlet,传入名称和资源组,并为 Primary 参数指定 SecondaryKeyType。 以下示例重新生成缓存的辅助访问密钥。

    PS C:\> New-AzRedisEnterpriseCacheKey -Name myCache -ResourceGroupName myGroup -KeyType Secondary

    Confirm
    Are you sure you want to regenerate Secondary key for Azure Managed Redis 'myCache'?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y


    PrimaryKey   : b2wdt43sfetlju4hfbryfnregrd9wgIcc6IA3zAO1lY=
    SecondaryKey : c53hj3kh4jhHjPJk8l0jji785JgKH9865eifmekfnn6=

删除 Azure 托管的 Redis

若要删除 Azure 托管 Redis,请使用 Remove-AzRedisEnterpriseCache cmdlet。

若要查看 Remove-AzRedisEnterpriseCache的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help Remove-AzRedisEnterpriseCache -detailed

    NAME
        Remove-AzRedisEnterpriseCache

    SYNOPSIS
        Remove Azure Managed Redis if exists.

    SYNTAX
        Remove-AzRedisEnterpriseCache -Name <String> -ResourceGroupName <String> [-Force] [-PassThru] [<CommonParameters>

    DESCRIPTION
        The Remove-AzRedisEnterpriseCache cmdlet removes an Azure Managed Redis if it exists.

    PARAMETERS
        -Name <String>
            Name of the Azure Managed 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-AzRedisEnterpriseCache removes the cache and does not return any value. If the PassThru par
            is provided then Remove-AzRedisEnterpriseCache 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 的缓存。

    PS C:\> Remove-AzRedisEnterpriseCache -Name myCache -ResourceGroupName myGroup

    Confirm
    Are you sure you want to remove Azure Managed Redis 'myCache'?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

导入 Azure 托管的 Redis

可以使用 Import-AzRedisEnterpriseCache cmdlet 将数据导入 Azure 托管 Redis 实例。

若要查看 Import-AzRedisEnterpriseCache的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help Import-AzRedisEnterpriseCache -detailed

    NAME
        Import-AzRedisEnterpriseCache

    SYNOPSIS
        Import data from blobs to Azure Managed Redis.


    SYNTAX
        Import-AzRedisEnterpriseCache -Name <String> -ResourceGroupName <String> -Files <String[]> [-Format <String>] [-Force]
        [-PassThru] [<CommonParameters>]


    DESCRIPTION
        The Import-AzRedisEnterpriseCache cmdlet imports data from the specified blobs into Azure Managed 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-AzRedisEnterpriseCache imports data in cache and does not return any value. If the PassThru
            parameter is provided then Import-AzRedisEnterpriseCache 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 中。

    PS C:\>Import-AzRedisEnterpriseCache -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

可以使用 Export-AzRedisEnterpriseCache cmdlet 将数据从 Azure 托管 Redis 实例导出。

若要查看 Export-AzRedisEnterpriseCache的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help Export-AzRedisEnterpriseCache -detailed

    NAME
        Export-AzRedisEnterpriseCache

    SYNOPSIS
        Exports data from Azure Managed Redis to a specified container.


    SYNTAX
        Export-AzRedisEnterpriseCache -Name <String> -ResourceGroupName <String> -Prefix <String> -Container <String> [-Format
        <String>] [-PassThru] [<CommonParameters>]


    DESCRIPTION
        The Export-AzRedisEnterpriseCache cmdlet exports data from Azure Managed 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-AzRedisEnterpriseCache does not return any value. If the PassThru parameter is provided
            then Export-AzRedisEnterpriseCache 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 所指定的容器中。

    PS C:\>Export-AzRedisEnterpriseCache -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(预览版)

可以使用 Reset-AzRedisEnterpriseCache cmdlet 重启 Azure 托管 Redis(预览版)实例。

若要查看 Reset-AzRedisEnterpriseCache的可用参数列表及其说明,请运行以下命令。

    PS C:\> Get-Help Reset-AzRedisEnterpriseCache -detailed

    NAME
        Reset-AzRedisEnterpriseCache

    SYNOPSIS
        Reboot specified node(s) of an Azure Managed Redis instance.


    SYNTAX
        Reset-AzRedisEnterpriseCache -Name <String> -ResourceGroupName <String> -RebootType <String> [-ShardId <Integer>]
        [-Force] [-PassThru] [<CommonParameters>]


    DESCRIPTION
        The Reset-AzRedisEnterpriseCache cmdlet reboots the specified node(s) of an Azure Managed 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 cache with clustering enabled.

        -Force
            When the Force parameter is provided, reset will be performed without any confirmation prompts.

        -PassThru
            By default Reset-AzRedisEnterpriseCache does not return any value. If the PassThru parameter is provided
            then Reset-AzRedisEnterpriseCache 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).

以下命令重新启动指定缓存的两个节点。

    PS C:\>Reset-AzRedisEnterpriseCache -ResourceGroupName "resourceGroupName" -Name "cacheName" -RebootType "AllNodes"
    -Force

注释

Azure 提供两种不同的部署模型用于创建和处理资源:Azure 资源管理器模型和经典模型。 本文介绍了资源管理器部署模型的使用。 对于新部署,建议使用资源管理器部署模型而非经典部署模型。

有关经典部署模型的详细信息,请参阅 Azure 资源管理器与经典部署:了解部署模型和资源状态

先决条件

如果已安装 Azure PowerShell,则必须确保安装的是 Azure PowerShell 版本 1.0.0 或更高版本。 可在 Azure PowerShell 命令提示符处使用以下命令查看 Azure PowerShell 版本。

    Get-Module Az | format-table version

首先,必须使用以下命令登录到 Azure。

    Connect-AzAccount -Environment AzureChinaCloud

在 Azure 登录对话框中指定 Azure 帐户的电子邮件地址和密码。

接下来,如果有多个 Azure 订阅,则需要设置 Azure 订阅。 若要查看当前订阅的列表,请运行以下命令。

    Get-AzSubscription | sort SubscriptionName | Select SubscriptionName

若要指定订阅,请运行以下命令。 在以下示例中,订阅名为 ContosoSubscription

    Select-AzSubscription -SubscriptionName ContosoSubscription

在可以将 Windows PowerShell 与 Azure 资源管理器一起使用之前,需验证你的设置:

  • Windows PowerShell 3.0 版或 4.0 版。 若要查找 Windows PowerShell 的版本,请键入:$PSVersionTable 并验证 PSVersion 的值是否为 3.0 或 4.0。 若要安装兼容版本,请参阅 Windows Management Framework 3.0

要获取你在本教程中看到的任何 cmdlet 的详细帮助信息,请使用 Get-Help cmdlet。

    Get-Help <cmdlet-name> -Detailed

例如,若要获取有关 New-AzRedisCache cmdlet 的帮助,请键入:

    Get-Help New-AzRedisCache -Detailed

如何连接到其他云

默认情况下,Azure 环境是 AzureCloud,它表示全局 Azure 云实例。 若要连接到其他实例,请结合使用 Connect-AzAccount-Environment 或结合使用 -EnvironmentName 命令行开关与所需环境或环境名称。

若要查看可用环境列表,请运行 Get-AzEnvironment cmdlet。

连接到由世纪互联运营的 Microsoft Azure

若要连接到由世纪互联运营的 Microsoft Azure,请使用以下命令之一。

    Connect-AzAccount -EnvironmentName AzureChinaCloud

    Connect-AzAccount -Environment (Get-AzEnvironment -Name AzureChinaCloud)

若要在由世纪互联云运营的 Microsoft Azure 中创建缓存,请使用以下位置之一。

  • 中国东部
  • 中国北部

Azure Cache for Redis PowerShell 使用的属性

下表包含创建和管理 Azure Cache for Redis 实例时常用的参数的 Azure PowerShell 属性和说明。

参数 DESCRIPTION 违约
名称 缓存的名称
位置 缓存的位置
资源组名称 要在其中创建缓存的资源组名称
尺寸 缓存的大小。 有效值为:P1、P2、P3、P4、P5、C0、C1、C2、C3、C4、C5、C6、250MB、1GB、2.5GB、6GB、13GB、26GB、53GB 1GB
ShardCount 在启用群集的情况下创建高级缓存时要创建的分片数目。 有效值是:1、2、3、4、5、6、7、8、9、10
SKU 指定缓存的 SKU。 有效值是:Basic、Standard、Premium 标准
RedisConfiguration 指定 Redis 配置设置。 有关每个设置的详细信息,请参阅以下 RedisConfiguration 属性表。
启用非SSL端口 指出是否启用非 SSL 端口。
MaxMemoryPolicy 此参数已弃用 - 请改用 RedisConfiguration。
StaticIP 在 VNET 中托管缓存时,指定缓存在子网中的唯一 IP 地址。 如果未提供此值,系统将从子网中为你选择一个。
子网 在 VNET 中托管缓存时,指定要在其中部署缓存的子网。
虚拟网络 在 VNET 中托管缓存时,指定要在其中部署缓存的 VNET 的资源 ID。
按键类型 指定在续订访问密钥时需要重新生成的访问密钥。 有效值是:主要、次要

RedisConfiguration 属性

资产 DESCRIPTION 定价层级
rdb-backup-enabled 是否启用了 [Redis 数据持久性]/azure-cache-for-redis/cache-how-to-premium-persistence.md) 仅限高级用户
rdb-storage-connection-string 用于 [Redis 数据持久性]/azure-cache-for-redis/cache-how-to-premium-persistence.md)的存储帐户的连接字符串 仅限高级用户
rdb备份频率 [Redis 数据持久性]/azure-cache-for-redis/cache-how-to-premium-persistence.md)的备份频率 仅限高级用户
maxmemory-reserved 为非缓存进程配置 [预留的内存]/azure-cache-for-redis/cache-configure.md#memory-policies) 标准版和高级版
最大内存策略 (maxmemory-policy) 为缓存配置 [逐出策略]/azure-cache-for-redis/cache-configure.md#memory-policies) 所有定价层
notify-keyspace-events 配置 [密钥空间通知]/azure-cache-for-redis/cache-configure.md#keyspace-notifications-advanced-settings) 标准版和高级版
hash-max-ziplist-entries 为较小的聚合数据类型配置 内存优化 标准版和高级版
hash-max-ziplist-value 为较小的聚合数据类型配置 内存优化 标准版和高级版
set-max-intset-entries 为较小的聚合数据类型配置 内存优化 标准版和高级版
zset-max-ziplist-entries 为较小的聚合数据类型配置 内存优化 标准版和高级版
zset-max-ziplist-value 为较小的聚合数据类型配置 内存优化 标准版和高级版
数据库 配置数据库的数目。 该属性只能在创建缓存时配置。 标准版和高级版

创建 Azure Redis 缓存

可以使用 New-AzRedisCache cmdlet 创建新的 Azure Redis 缓存实例。

重要

第一次使用 Azure 门户在订阅中创建 Azure Redis 缓存时,门户将为该订阅注册 Microsoft.Cache 命名空间。 如果尝试使用 PowerShell 在订阅中创建第一个 Azure Redis 缓存,必须首先使用以下命令注册命名空间;否则,诸如 New-AzRedisCacheGet-AzRedisCache 的 cmdlet 会失败。

Register-AzResourceProvider -ProviderNamespace "Microsoft.Cache"

若要查看 New-AzRedisCache的可用参数列表及其说明,请运行以下命令。

    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).

若要使用默认参数创建缓存,请运行以下命令。

    New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "China North"

ResourceGroupNameNameLocation 是必需的参数,其余则是可选参数并且有默认值。 运行前面的命令会使用指定的名称、位置和资源组创建标准 SKU Azure Cache for Redis 实例。 实例的大小为 1 GB,且禁用了非 SSL 端口。

若要创建高级缓存,请指定大小 P1 (6 GB - 60 GB)、P2 (13 GB - 130 GB)、P3 (26 GB - 260 GB) 或 P4 (53 GB - 530 GB)。 若要启用群集,使用 ShardCount 参数指定分片计数。 以下示例将创建包含 3 个分片的 P1 高级缓存。 P1 高级缓存的大小为 6 GB。由于我们指定了 3 个分片,因此总大小为 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"}。 以下示例将创建标准 1 GB 缓存,其包含 allkeys-random maxmemory 策略,以及使用 KEA 配置的 keyspace 通知。 有关详细信息,请参阅 [密钥空间通知(高级设置)]/azure-cache-for-redis/cache-configure.md#keyspace-notifications-advanced-settings)和[内存策略]/azure-cache-for-redis/cache-configure.md#memory-policies)。

    New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "China North" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}

在缓存创建过程中配置数据库设置

databases 设置只能在缓存创建过程中配置。 下面的示例使用 New-AzRedisCache cmdlet 创建包含 48 个数据库的高级 P3 (26 GB) 缓存。

    New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "China North" -Sku Premium -Size P3 -RedisConfiguration @{"databases" = "48"}

有关 databases 属性的详细信息,请参阅[Azure Redis 缓存默认服务器配置](/azure-cache-for-redis/cache-configure.md#default-redis-server-configuration)。 有关使用 New-AzRedisCache cmdlet 创建缓存的详细信息,请参阅前面的创建 Azure Redis 缓存部分。

更新 Azure Cache for Redis

可以使用 Set-AzRedisCache cmdlet 更新 Azure Redis 缓存实例。

若要查看 Set-AzRedisCache的可用参数列表及其说明,请运行以下命令。

    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 可用于更新属性,例如 SizeSkuEnableNonSslPortRedisConfiguration 值。

以下命令将更新名为 myCache 的 Azure Cache for Redis 的最大内存策略 (maxmemory-policy)。

    Set-AzRedisCache -ResourceGroupName "myGroup" -Name "myCache" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random"}

缩放 Azure Cache for Redis

修改 Set-AzRedisCacheSizeSku 属性时,可以使用 ShardCount 来缩放 Azure Redis 缓存实例。

注释

使用 PowerShell 缩放缓存受到的限制和要遵循的准则与在 Azure 门户中缩放缓存相同。 可以扩展到不同定价层,但有以下限制。

  • 不能从较高的定价层缩放到较低的定价层。
  • 不能从高级缓存向下缩放到标准基本缓存。
  • 不能将一个标准缓存降级为基本缓存。
  • 可从基本缓存缩放到标准缓存,但不能同时更改大小。 如果需要不同大小,则可以执行后续缩放操作以缩放为所需大小。
  • 不能从基本缓存直接缩放到高级缓存。 必须在一个缩放操作中从基本缩放到标准,并在后续的缩放操作中从标准缩放到高级
  • 不能从较大的大小减小为 C0 (250 MB)

有关详细信息,请参阅 [如何缩放 Azure Redis 缓存]/azure-cache-for-redis/cache-how-to-scale.md)。

以下示例演示如何将名为 myCache 的缓存缩放为 2.5-GB 缓存。 此命令适用于基本或标准缓存。

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

发出此命令之后,将返回缓存的状态(类似于调用 Get-AzRedisCache)。 ProvisioningState 设置为 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。 如果需要进行其他缩放操作,例如先从基本缓存更改为标准缓存,再更改大小,则必须等到前面操作完成,否则会收到类似于下面的错误。

    Set-AzRedisCache : Conflict: The resource '...' is not in a stable state, and is currently unable to accept the update request.

获取有关 Azure Redis 缓存的信息

可以使用 Get-AzRedisCache cmdlet 检索有关缓存的信息。

若要查看 Get-AzRedisCache的可用参数列表及其说明,请运行以下命令。

    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

    Get-AzRedisCache

若要返回特定资源组中所有缓存的相关信息,请结合 Get-AzRedisCache 参数运行 ResourceGroupName

    Get-AzRedisCache -ResourceGroupName myGroup

若要返回特定缓存的相关信息,请运行 Get-AzRedisCache,并使用包含缓存名称的 Name 参数,和包含该缓存所在资源组的 ResourceGroupName 参数。

    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 缓存的访问密钥

若要检索缓存的访问密钥,可以使用 Get-AzRedisCacheKey cmdlet。

若要查看 Get-AzRedisCacheKey的可用参数列表及其说明,请运行以下命令。

    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,并传递缓存的名称以及包含该缓存的资源组的名称。

    PS C:\> Get-AzRedisCacheKey -Name myCache -ResourceGroupName myGroup

    PrimaryKey   : b2wdt43sfetlju4hfbryfnregrd9wgIcc6IA3zAO1lY=
    SecondaryKey : ABhfB757JgjIgt785JgKH9865eifmekfnn649303JKL=

再生成 Azure Cache for Redis 的访问密钥

若要重新生成缓存的访问密钥,可以使用 New-AzRedisCacheKey cmdlet。

若要查看 New-AzRedisCacheKey的可用参数列表及其说明,请运行以下命令。

    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,传入名称和资源组,并为 Primary 参数指定 SecondaryKeyType。 以下示例重新生成缓存的辅助访问密钥。

    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 Cache for Redis

若要删除 Azure Redis 缓存,请使用 Remove-AzRedisCache cmdlet。

若要查看 Remove-AzRedisCache的可用参数列表及其说明,请运行以下命令。

    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 的缓存。

    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 Cache for Redis

可以使用 Import-AzRedisCache cmdlet 将数据导入 Azure Redis 缓存实例。

重要

导入/导出仅适用于 [高级层]/azure-cache-for-redis/cache-overview.md#service-tiers)缓存。 有关导入/导出的详细信息,请参阅 [Azure Cache for Redis 中的导入和导出数据]/azure-cache-for-redis/cache-how-to-import-export-data.md)。

若要查看 Import-AzRedisCache的可用参数列表及其说明,请运行以下命令。

    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 缓存中。

    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 Cache for Redis

可以使用 Export-AzRedisCache cmdlet 将数据从 Azure Redis 缓存实例导出。

重要

导入/导出仅适用于 [高级层]/azure-cache-for-redis/cache-overview.md#service-tiers)缓存。 有关导入/导出的详细信息,请参阅 [Azure Cache for Redis 中的导入和导出数据]/azure-cache-for-redis/cache-how-to-import-export-data.md)。

若要查看 Export-AzRedisCache的可用参数列表及其说明,请运行以下命令。

    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 所指定的容器中。

    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 缓存

可以使用 Reset-AzRedisCache cmdlet 重启 Azure Redis 缓存实例。

重要

重新启动仅适用于 [基本层、标准和高级层]/azure-cache-for-redis/cache-overview.md#service-tiers) 缓存。 有关重新启动缓存的详细信息,请参阅 [缓存管理 - 重新启动]/azure-cache-for-redis/cache-administration.md#reboot)。

若要查看 Reset-AzRedisCache的可用参数列表及其说明,请运行以下命令。

    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).

以下命令重新启动指定缓存的两个节点。

    PS C:\>Reset-AzRedisCache -ResourceGroupName "resourceGroupName" -Name "cacheName" -RebootType "AllNodes"
    -Force

后续步骤

要了解有关将 Windows PowerShell 与 Azure 配合使用的详细信息,请参阅以下资源: