如何使用 Azure 经典 CLI 创建和管理 Azure Redis 缓存How to create and manage Azure Cache for Redis using the Azure classic CLI

Azure 经典 CLI 是从任何平台管理 Azure 基础结构的好办法。The Azure classic CLI is a great way to manage your Azure infrastructure from any platform. 本文演示了如何使用 Azure 经典 CLI 创建和管理 Azure Redis 缓存实例。This article shows you how to create and manage your Azure Cache for Redis instances using the Azure classic CLI.

重要

本文包含需要 Azure 经典 CLI 的内容。This article contains content which requires the Azure classic CLI. 这是 Azure CLI 的旧版本,只能与 Azure 经典部署模型一起使用。This is an older version of the Azure CLI that should be used only with the Azure classic deployment model.

若要安装经典 CLI,请参阅安装 Azure 经典 CLI;若要安装最新 Azure CLI 以进行 Azure 资源管理器部署,请参阅安装 Azure CLITo install the classic CLI, see Install the Azure classic CLI and to install the current Azure CLI for Azure Resource Manager deployments, see Install Azure CLI.

备注

有关最新的 Azure CLI 示例脚本,请参阅 Azure Redis 缓存示例For the latest Azure CLI sample scripts, see Azure CLI Azure Cache for Redis samples.

先决条件Prerequisites

要使用 Azure 经典 CLI 创建和管理 Azure Redis 缓存实例,必须完成以下步骤。To create and manage Azure Cache for Redis instances using Azure classic CLI, you must complete the following steps.

  • 必须具有 Azure 帐户。You must have an Azure account. 如果没有帐户,只需几分钟就能创建一个试用帐户If you don't have one, you can create a Trial in just a few moments.
  • 安装 Azure 经典 CLIInstall the Azure classic CLI.
  • 将 Azure CLI 安装与个人 Azure 帐户或者工作或学校 Azure 帐户关联,然后使用 azure login 命令从经典 CLI 登录。Connect your Azure CLI installation with a personal Azure account, or with a work or school Azure account, and log in from the classic CLI using the azure login command.
  • 在运行以下任何命令之前,通过运行 azure config mode arm 命令将经典 CLI 切换到资源管理器模式下。Before running any of the following commands, switch the classic CLI into Resource Manager mode by running the azure config mode arm command. 有关更多详细信息,请参阅使用 Azure 经典 CLI 管理 Azure 资源和资源组For more information, see Use the Azure classic CLI to manage Azure resources and resource groups.

Azure Redis 缓存属性Azure Cache for Redis properties

在创建和更新 Azure Redis 缓存实例时使用以下属性。The following properties are used when creating and updating Azure Cache for Redis instances.

属性Property 开关Switch 说明Description
namename -n, --name-n, --name Azure Redis 缓存的名称。Name of the Azure Cache for Redis.
资源组resource group -g, --resource-group-g, --resource-group 资源组的名称。Name of the Resource Group.
位置location -l, --location-l, --location 要创建缓存的位置。Location to create cache.
大小size -z, --size-z, --size Azure Redis 缓存的大小。Size of the Azure Cache for Redis. 有效的值:[C0、C1、C2、C3、C4、C5、C6、P1、P2、P3、P4]Valid values: [C0, C1, C2, C3, C4, C5, C6, P1, P2, P3, P4]
skusku -x, --sku-x, --sku Redis SKU。Redis SKU. 应为以下值之一:[Basic、Standard、Premium]Should be one of : [Basic, Standard, Premium]
EnableNonSslPortEnableNonSslPort -e, --enable-non-ssl-port-e, --enable-non-ssl-port Azure Redis 缓存的 EnableNonSslPort 属性。EnableNonSslPort property of the Azure Cache for Redis. 如果要为缓存启用非 TLS/SSL 端口,请添加此标志Add this flag if you want to enable the non-TLS/SSL Port for your cache
Redis 配置Redis Configuration -c, --redis-configuration-c, --redis-configuration Redis 配置。Redis Configuration. 在此处输入配置键和值的 JSON 格式字符串。Enter a JSON formatted string of configuration keys and values here. 格式:"{"":"","":""}"Format:"{"":"","":""}"
Redis 配置Redis Configuration -f, --redis-configuration-file-f, --redis-configuration-file Redis 配置。Redis Configuration. 在此处输入包含配置键和值的文件的路径。Enter the path of a file containing configuration keys and values here. 文件输入项的格式:{"":"","":""}Format for the file entry: {"":"","":""}
分片计数Shard Count -r, --shard-count-r, --shard-count 要在启用群集的高级群集缓存上创建的分片数。Number of Shards to create on a Premium Cluster Cache with clustering.
虚拟网络Virtual Network -v, --virtual-network-v, --virtual-network 在 VNet 中托管缓存时,指定要在其中部署 Azure Redis 缓存的虚拟网络的确切 ARM 资源 ID。When hosting your cache in a VNET, specifies the exact ARM resource ID of the virtual network to deploy the Azure Cache for Redis in. 格式示例:/subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.ClassicNetwork/VirtualNetworks/vnet1Example format: /subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.ClassicNetwork/VirtualNetworks/vnet1
密钥类型key type -t, --key-type-t, --key-type 要续订的密钥类型。Type of key to renew. 有效值:[Primary、Secondary]Valid values: [Primary, Secondary]
StaticIPStaticIP -p, --static-ip <static-ip>-p, --static-ip <static-ip> 在 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 t, --subnet <subnet>t, --subnet <subnet> 在 VNET 中托管缓存时,指定要在其中部署缓存的子网。When hosting your cache in a VNET, specifies the name of the subnet in which to deploy the cache.
VirtualNetworkVirtualNetwork -v, --virtual-network <virtual-network>-v, --virtual-network <virtual-network> 在 VNet 中托管缓存时,指定要在其中部署 Azure Redis 缓存的虚拟网络的确切 ARM 资源 ID。When hosting your cache in a VNET, specifies the exact ARM resource ID of the virtual network to deploy the Azure Cache for Redis in. 格式示例:/subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.ClassicNetwork/VirtualNetworks/vnet1Example format: /subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.ClassicNetwork/VirtualNetworks/vnet1
订阅Subscription -s, --subscription-s, --subscription 订阅标识符。The subscription identifier.

查看所有 Azure Redis 缓存命令See all Azure Cache for Redis commands

要查看所有 Azure Redis 缓存命令及其参数,请使用 azure rediscache -h 命令。To see all Azure Cache for Redis commands and their parameters, use the azure rediscache -h command.

C:\>azure rediscache -h
help:    Commands to manage your Azure Cache for Redis(s)
help:
help:    Create an Azure Cache for Redis
help:      rediscache create [--name <name> --resource-group <resource-group> --location <location> [options]]
help:
help:    Delete an existing Azure Cache for Redis
help:      rediscache delete [--name <name> --resource-group <resource-group> ]
help:
help:    List all Azure Cache for Redis within your Subscription or Resource Group
help:      rediscache list [options]
help:
help:    Show properties of an existing Azure Cache for Redis
help:      rediscache show [--name <name> --resource-group <resource-group>]
help:
help:    Change settings of an existing Azure Cache for Redis
help:      rediscache set [--name <name> --resource-group <resource-group> --redis-configuration <redis-configuration>/--redis-configuration-file <redisConfigurationFile>]
help:
help:    Renew the authentication key for an existing Azure Cache for Redis
help:      rediscache renew-key [--name <name> --resource-group <resource-group> ]
help:
help:    Lists Primary and Secondary key of an existing Azure Cache for Redis
help:      rediscache list-keys [--name <name> --resource-group <resource-group>]
help:
help:    Options:
help:      -h, --help  output usage information
help:
help:    Current Mode: arm (Azure Resource Management)

创建 Azure Redis 缓存Create an Azure Cache for Redis

要创建 Azure Redis 缓存,请使用以下命令:To create an Azure Cache for Redis, use the following command:

    azure rediscache create [--name <name> --resource-group <resource-group> --location <location> [options]]

有关此命令的详细信息,请运行 azure rediscache create -h 命令。For more information about this command, run the azure rediscache create -h command.

C:\>azure rediscache create -h
help:    Create an Azure Cache for Redis
help:
help:    Usage: rediscache create [--name <name> --resource-group <resource-group> --location <location> [options]]
help:
help:    Options:
help:      -h, --help                                               output usage information
help:      -v, --verbose                                            use verbose output
help:      -vv                                                      more verbose with debug output
help:      --json                                                   use json output
help:      -n, --name <name>                                        Name of the Azure Cache for Redis.
help:      -g, --resource-group <resource-group>                    Name of the Resource Group
help:      -l, --location <location>                                Location to create cache.
help:      -z, --size <size>                                        Size of the Azure Cache for Redis. Valid values: [C0, C1, C2, C3, C4, C5, C6, P1, P2, P3, P4]
help:      -x, --sku <sku>                                          Redis SKU. Should be one of : [Basic, Standard, Premium]
help:      -e, --enable-non-ssl-port                                EnableNonSslPort property of the Azure Cache for Redis. Add this flag if you want to enable the non-TLS/SSL Port for your cache
help:      -c, --redis-configuration <redis-configuration>          Redis Configuration. Enter a JSON formatted string of configuration keys and values here. Format:"{"<key1>":"<value1>","<key2>":"<value2>"}"
help:      -f, --redis-configuration-file <redisConfigurationFile>  Redis Configuration. Enter the path of a file containing configuration keys and values here. Format for the file entry: {"<key1>":"<value1>","<key2>":"<value2>"}
help:      -r, --shard-count <shard-count>                          Number of Shards to create on a Premium Cluster Cache
help:      -v, --virtual-network <virtual-network>                  The exact ARM resource ID of the virtual network to deploy the Azure Cache for Redis in. Example format: /subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.ClassicNetwork/VirtualNetworks/vnet1
help:      -t, --subnet <subnet>                                    Required when deploying an Azure Cache for Redis inside an existing Azure Virtual Network
help:      -p, --static-ip <static-ip>                              Required when deploying an Azure Cache for Redis inside an existing Azure Virtual Network
help:      -s, --subscription <id>                                  the subscription identifier
help:
help:    Current Mode: arm (Azure Resource Management)

删除现有的 Azure Redis 缓存Delete an existing Azure Cache for Redis

要删除 Azure Redis 缓存,请使用以下命令:To delete an Azure Cache for Redis, use the following command:

    azure rediscache delete [--name <name> --resource-group <resource-group> ]

有关此命令的详细信息,请运行 azure rediscache delete -h 命令。For more information about this command, run the azure rediscache delete -h command.

C:\>azure rediscache delete -h
help:    Delete an existing Azure Cache for Redis
help:
help:    Usage: rediscache delete [--name <name> --resource-group <resource-group> ]
help:
help:    Options:
help:      -h, --help                             output usage information
help:      -v, --verbose                          use verbose output
help:      -vv                                    more verbose with debug output
help:      --json                                 use json output
help:      -n, --name <name>                      Name of the Azure Cache for Redis.
help:      -g, --resource-group <resource-group>  Name of the Resource Group under which the cache exists
help:      -s, --subscription <subscription>      the subscription identifier
help:
help:    Current Mode: arm (Azure Resource Management)

列出订阅或资源组中的所有 Azure Redis 缓存List all Azure Cache for Redis within your Subscription or Resource Group

要列出订阅或资源组中的所有 Azure Redis 缓存,请使用以下命令:To list all Azure Cache for Redis within your Subscription or Resource Group, use the following command:

    azure rediscache list [options]

有关此命令的详细信息,请运行 azure rediscache list -h 命令。For more information about this command, run the azure rediscache list -h command.

C:\>azure rediscache list -h
help:    List all Azure Cache for Redis within your Subscription or Resource Group
help:
help:    Usage: rediscache list [options]
help:
help:    Options:
help:      -h, --help                             output usage information
help:      -v, --verbose                          use verbose output
help:      -vv                                    more verbose with debug output
help:      --json                                 use json output
help:      -g, --resource-group <resource-group>  Name of the Resource Group
help:      -s, --subscription <subscription>      the subscription identifier
help:
help:    Current Mode: arm (Azure Resource Management)

显示现有 Azure Redis 缓存的属性Show properties of an existing Azure Cache for Redis

要显示现有 Azure Redis 缓存的属性,请使用以下命令:To show properties of an existing Azure Cache for Redis, use the following command:

    azure rediscache show [--name <name> --resource-group <resource-group>]

有关此命令的详细信息,请运行 azure rediscache show -h 命令。For more information about this command, run the azure rediscache show -h command.

C:\>azure rediscache show -h
help:    Show properties of an existing Azure Cache for Redis
help:
help:    Usage: rediscache show [--name <name> --resource-group <resource-group>]
help:
help:    Options:
help:      -h, --help                             output usage information
help:      -v, --verbose                          use verbose output
help:      -vv                                    more verbose with debug output
help:      --json                                 use json output
help:      -n, --name <name>                      Name of the Azure Cache for Redis.
help:      -g, --resource-group <resource-group>  Name of the Resource Group
help:      -s, --subscription <subscription>      the subscription identifier
help:
help:    Current Mode: arm (Azure Resource Management)

更改 Azure Redis 缓存的属性设置Change settings of an existing Azure Cache for Redis

更改现有 Azure Redis 缓存的属性设置,请使用以下命令:To change settings of an existing Azure Cache for Redis, use the following command:

    azure rediscache set [--name <name> --resource-group <resource-group> --redis-configuration <redis-configuration>/--redis-configuration-file <redisConfigurationFile>]

有关此命令的详细信息,请运行 azure rediscache set -h 命令。For more information about this command, run the azure rediscache set -h command.

C:\>azure rediscache set -h
help:    Change settings of an existing Azure Cache for Redis
help:
help:    Usage: rediscache set [--name <name> --resource-group <resource-group> --redis-configuration <redis-configuration>/--redis-configuration-file <redisConfigurationFile>]
help:
help:    Options:
help:      -h, --help                                               output usage information
help:      -v, --verbose                                            use verbose output
help:      -vv                                                      more verbose with debug output
help:      --json                                                   use json output
help:      -n, --name <name>                                        Name of the Azure Cache for Redis.
help:      -g, --resource-group <resource-group>                    Name of the Resource Group
help:      -c, --redis-configuration <redis-configuration>          Redis Configuration. Enter a JSON formatted string of configuration keys and values here.
help:      -f, --redis-configuration-file <redisConfigurationFile>  Redis Configuration. Enter the path of a file containing configuration keys and values here.
help:      -s, --subscription <subscription>                        the subscription identifier
help:
help:    Current Mode: arm (Azure Resource Management)

为现有 Azure Redis 缓存续订身份验证密钥Renew the authentication key for an existing Azure Cache for Redis

要为现有 Azure Redis 缓存续订身份验证密钥,请使用以下命令:To renew the authentication key for an existing Azure Cache for Redis, use the following command:

    azure rediscache renew-key [--name <name> --resource-group <resource-group> --key-type <key-type>]

key-type 指定 PrimarySecondarySpecify Primary or Secondary for key-type.

有关此命令的详细信息,请运行 azure rediscache renew-key -h 命令。For more information about this command, run the azure rediscache renew-key -h command.

C:\>azure rediscache renew-key -h
help:    Renew the authentication key for an existing Azure Cache for Redis
help:
help:    Usage: rediscache renew-key [--name <name> --resource-group <resource-group> ]
help:
help:    Options:
help:      -h, --help                             output usage information
help:      -v, --verbose                          use verbose output
help:      -vv                                    more verbose with debug output
help:      --json                                 use json output
help:      -n, --name <name>                      Name of the Azure Cache for Redis.
help:      -g, --resource-group <resource-group>  Name of the Resource Group under which cache exists
help:      -t, --key-type <key-type>              type of key to renew. Valid values are: 'Primary', 'Secondary'.
help:      -s, --subscription <subscription>      the subscription identifier
help:
help:    Current Mode: arm (Azure Resource Management)

列出现有 Azure Redis 缓存的主密钥和辅助密钥List Primary and Secondary keys of an existing Azure Cache for Redis

要列出现有 Azure Redis 缓存的主密钥和辅助密钥,请使用以下命令:To list Primary and Secondary keys of an existing Azure Cache for Redis, use the following command:

    azure rediscache list-keys [--name <name> --resource-group <resource-group>]

有关此命令的详细信息,请运行 azure rediscache list-keys -h 命令。For more information about this command, run the azure rediscache list-keys -h command.

C:\>azure rediscache list-keys -h
help:    Lists Primary and Secondary key of an existing Azure Cache for Redis
help:
help:    Usage: rediscache list-keys [--name <name> --resource-group <resource-group>]
help:
help:    Options:
help:      -h, --help                             output usage information
help:      -v, --verbose                          use verbose output
help:      -vv                                    more verbose with debug output
help:      --json                                 use json output
help:      -n, --name <name>                      Name of the Azure Cache for Redis.
help:      -g, --resource-group <resource-group>  Name of the Resource Group under which Cache exists
help:      -s, --subscription <subscription>      the subscription identifier
help:
help:    Current Mode: arm (Azure Resource Management)