使用 Azure PowerShell 管理 Azure Cache for Redis
本文說明如何建立、更新及調整 Azure Cache for Redis 實例。 本文也會示範如何重新產生存取密鑰,以及如何檢視快取的相關信息。 如需 Azure Cache for Redis PowerShell Cmdlet 的完整清單,請參閱 Azure Cache for Redis Cmdlet。
注意
Azure 有兩種不同的部署模型,可用來建立和處理資源:Azure Resource Manager 和傳統模型。 本文涵蓋了 Resource Manager 部署模型的使用。 建議您針對新部署使用 Resource Manager 部署模型,而不是傳統部署模型。
如需傳統部署模型的詳細資訊,請參閱 Azure Resource Manager 與傳統部署:瞭解部署模型和資源的狀態。
必要條件
如果您已安裝 Azure PowerShell,則必須有 Azure PowerShell 1.0.0 版或更新版本。 您可以在 Azure PowerShell 命令提示字元中,使用此命令來檢查 Azure PowerShell 的版本。
Get-Module Az | format-table version
首先,您必須使用此命令登入 Azure。
Connect-AzAccount
在 [Microsoft Azure 登入] 對話框中指定 Azure 帳戶的電子郵件地址和密碼。
接下來,如果您有多個 Azure 訂用帳戶,則必須設定您的 Azure 訂用帳戶。 若要查看目前訂用帳戶的清單,請執行此命令。
Get-AzSubscription | sort SubscriptionName | Select SubscriptionName
若要指定訂用帳戶,請執行下列命令。 在下列範例中,訂用帳戶名稱為 ContosoSubscription
。
Select-AzSubscription -SubscriptionName ContosoSubscription
您必須先確認您的設定,才能搭配 Azure Resource Manager 使用 Windows PowerShell:
- 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
例如,若要取得 Cmdlet 的說明 New-AzRedisCache
,請輸入:
Get-Help New-AzRedisCache -Detailed
如何連線到其他雲端
根據預設,Azure 環境是 AzureCloud
,代表全域 Azure 雲端實例。 若要連線到不同的實例,請使用 Connect-AzAccount
命令搭配 -Environment
或 -EnvironmentName
命令行參數搭配您想要的環境或環境名稱。
若要查看可用的環境清單,請執行 Get-AzEnvironment
Cmdlet。
聯機至 Azure Government 雲端
若要連線到 Azure Government Cloud,請使用下列其中一個命令。
Connect-AzAccount -EnvironmentName AzureUSGovernment
Or
Connect-AzAccount -Environment (Get-AzEnvironment -Name AzureUSGovernment)
若要在 Azure Government Cloud 中建立快取,請使用下列其中一個位置。
- USGov Virginia
- USGov 愛荷華州
如需 Azure Government Cloud 的詳細資訊,請參閱 Microsoft Azure Government 和 Microsoft Azure Government 開發人員指南。
聯機到由 21Vianet Cloud 運作的 Microsoft Azure
若要連線到由 21Vianet 雲端運作的 Azure,請使用下列其中一個命令。
Connect-AzAccount -EnvironmentName AzureChinaCloud
Or
Connect-AzAccount -Environment (Get-AzEnvironment -Name AzureChinaCloud)
若要在由 21Vianet Cloud 運作的 Azure 中建立快取,請使用下列其中一個位置。
- 中國東部
- 中國北部
連線至 Microsoft Azure 德國
若要連線到 Microsoft Azure 德國,請使用下列其中一個命令。
Connect-AzAccount -EnvironmentName AzureGermanCloud
Or
Connect-AzAccount -Environment (Get-AzEnvironment -Name AzureGermanCloud)
若要在 Microsoft Azure 德國建立快取,請使用下列其中一個位置。
- 德國中部
- 德國東北部
如需 Microsoft Azure 德國的詳細資訊,請參閱 Microsoft Azure 德國。
用於 Azure Cache for Redis PowerShell 的屬性
下表包含建立和管理 Azure Cache for Redis 實例時常見參數的 Azure PowerShell 屬性和描述。
參數 | 描述 | 預設 |
---|---|---|
名稱 | 快取的名稱 | |
Location | 快取的位置 | |
resourceGroupName | 要在其中建立快取的資源組名 | |
大小 | 快取的大小。 有效值為: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。 有效值為:基本、標準、進階版 | 標準 |
RedisConfiguration | 指定 Redis 組態設定。 如需每個設定的詳細資訊,請參閱下列 RedisConfiguration 屬性 數據表。 | |
EnableNonSslPort | 指出是否啟用非 SSL 埠。 | False |
MaxMemoryPolicy | 此參數已被取代 - 請改用 RedisConfiguration。 | |
StaticIP | 在 VNET 中裝載快取時,指定快取子網中的唯一 IP 位址。 如果未提供,則會從子網中為您選擇一個。 | |
子網路 | 在 VNET 中裝載快取時,指定要在其中部署快取的子網名稱。 | |
VirtualNetwork | 在 VNET 中裝載快取時,指定要在其中部署快取之 VNET 的資源識別碼。 | |
KeyType | 指定更新存取金鑰時要重新產生的存取金鑰。 有效值為:主要、次要 |
RedisConfiguration 屬性
屬性 | 說明 | 定價層 |
---|---|---|
已啟用 rdb-backup-enabled | 是否啟用 Redis 資料持續性 | 僅限進階 |
rdb-storage-connection-string | Redis 數據持續性記憶體帳戶的 連接字串 | 僅限進階 |
rdb-backup-frequency | Redis 數據持續性的 備份頻率 | 僅限進階 |
maxmemory-reserved | 設定保留給非快取進程的記憶體 | 標準和進階 |
maxmemory-policy | 設定快取的收回原則 | 所有定價層 |
notify-keyspace-events | 設定 keyspace 通知 | 標準和進階 |
hash-max-ziplist-entries | 設定小型匯總數據類型的記憶體優化 | 標準和進階 |
hash-max-ziplist-value | 設定小型匯總數據類型的記憶體優化 | 標準和進階 |
set-max-intset-entries | 設定小型匯總數據類型的記憶體優化 | 標準和進階 |
zset-max-ziplist-entries | 設定小型匯總數據類型的記憶體優化 | 標準和進階 |
zset-max-ziplist-value | 設定小型匯總數據類型的記憶體優化 | 標準和進階 |
資料庫 | 設定資料庫數目。 此屬性只能在快取建立時設定。 | 標準和進階 |
建立 Azure Cache for Redis
新的 Azure Cache for Redis 實例是使用 New-AzRedisCache Cmdlet 建立。
重要
第一次使用 Azure 入口網站 在訂用帳戶中建立 Azure Cache for Redis 時,入口網站會註冊該訂用帳戶的Microsoft.Cache
命名空間。 如果您嘗試使用 PowerShell 在訂用帳戶中建立第一個 Azure Cache for Redis,您必須先使用下列命令註冊該命名空間:否則,例如 New-AzRedisCache
和 Get-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 "North Central US"
ResourceGroupName
、 Name
和 Location
是必要參數,但其餘參數是選擇性的,而且具有預設值。 執行上述命令會建立具有指定名稱、位置和資源群組的標準 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
參數指定分區計數。 下列範例會建立具有三個分區的 P1 進階快取。 P1 進階快取的大小為 6 GB,因為我們指定了三個分區,因此總大小為 18 GB(3 x 6 GB)。
New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "North Central US" -Sku Premium -Size P1 -ShardCount 3
若要指定 參數的值 RedisConfiguration
,請將 值括在 內 {}
,做為索引鍵/值組,例如 @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}
。 下列範例會建立標準 1 GB 快取,並使用 allkeys-random
設定 maxmemory 原則和 keyspace 通知 KEA
。 如需詳細資訊,請參閱 Keyspace 通知(進階設定) 和 記憶體原則。
New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "North Central US" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random", "notify-keyspace-events" = "KEA"}
在快取建立期間設定資料庫設定
設定 databases
只能在快取建立期間進行設定。 下列範例會使用 New-AzRedisCache Cmdlet,建立具有 48 個資料庫的進階 P3 (26 GB) 快取。
New-AzRedisCache -ResourceGroupName myGroup -Name mycache -Location "North Central US" -Sku Premium -Size P3 -RedisConfiguration @{"databases" = "48"}
如需 屬性的詳細資訊 databases
,請參閱 預設 Azure Cache for Redis 伺服器組態。 如需使用 New-AzRedisCache Cmdlet 建立快取的詳細資訊,請參閱上一個< To create an Azure Cache for Redis>一節。
更新 Azure Cache for Redis
Azure Cache for Redis 實例會使用 Set-AzRedisCache Cmdlet 更新。
若要查看可用參數的清單及其描述 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 可用來更新屬性,例如 Size
、Sku
、 EnableNonSslPort
和 RedisConfiguration
值。
下列命令會更新名為 myCache 之 Azure Cache for Redis 的 maxmemory-policy。
Set-AzRedisCache -ResourceGroupName "myGroup" -Name "myCache" -RedisConfiguration @{"maxmemory-policy" = "allkeys-random"}
調整 Azure Cache for Redis
Set-AzRedisCache
當修改、 Sku
或 ShardCount
屬性時Size
,可用來調整 Azure Cache for Redis 實例。
注意
使用 PowerShell 調整快取受限於從 Azure 入口網站 調整快取的相同限制和指導方針。 您可以使用下列限制來調整為不同的定價層。
- 您無法從較高的定價層調整為較低的定價層。
- 您無法從 進階版 快取相應減少到標準或基本快取。
- 您無法從 標準 快取向下調整為 基本 快取。
- 您可以從基本快取調整為標準快取,但無法同時變更大小。 如果您需要不同的大小,您可以執行後續調整作業以達到所需的大小。
- 您無法直接從基本快取調整為 進階版 快取。 您必須在一個調整作業中從基本調整調整為標準,然後在後續的調整作業中從標準調整為 進階版。
- 您無法從較大的大小縮小到 C0 (250 MB) 大小。
如需詳細資訊,請參閱 如何調整 Azure Cache for Redis。
下列範例示範如何將名為 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 : South Central US
Type : Microsoft.Cache/Redis
HostName : mycache.redis.cache.windows.net
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 Cache for 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 : South Central US
Type : Microsoft.Cache/Redis
HostName : mycache.redis.cache.windows.net
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 Cache for 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
或 Secondary
KeyType
。 在下列範例中,會重新產生快取的次要存取密鑰。
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 Cache for 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
您可以使用 Cmdlet 將數據匯入 Azure Cache for Redis 實例 Import-AzRedisCache
。
重要
匯入/匯出 僅適用於 進階版 層快取。 如需 匯入/匯出 的詳細資訊,請參閱在 Azure Cache for Redis 中匯入和導出數據。
若要查看可用參數的清單及其描述 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 Cache for Redis。
PS C:\>Import-AzRedisCache -ResourceGroupName "resourceGroupName" -Name "cacheName" -Files @("https://mystorageaccount.blob.core.windows.net/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
您可以使用 Cmdlet 從 Azure Cache for Redis 實例 Export-AzRedisCache
匯出數據。
重要
匯入/匯出 僅適用於 進階版 層快取。 如需 匯入/匯出 的詳細資訊,請參閱在 Azure Cache for Redis 中匯入和導出數據。
若要查看可用參數的清單及其描述 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 Cache for Redis 實例匯出至 SAS URI 所指定的容器。
PS C:\>Export-AzRedisCache -ResourceGroupName "resourceGroupName" -Name "cacheName" -Prefix "blobprefix"
-Container "https://mystorageaccount.blob.core.windows.net/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 Cache for Redis
您可以使用 Cmdlet 重新啟動 Azure Cache for Redis 實例 Reset-AzRedisCache
。
重要
重新啟動僅適用於基本、標準和 進階版 層快取。 如需重新啟動快取的詳細資訊,請參閱 快取管理 - 重新啟動。
若要查看可用參數的清單及其描述 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
下一步
若要深入瞭解如何搭配 Azure 使用 Windows PowerShell,請參閱下列資源:
- MSDN 上的 Azure Cache for Redis Cmdlet 檔
- Azure Resource Manager Cmdlet:瞭解如何使用 Azure Resource Manager 模組中的 Cmdlet。
- 使用資源群組來管理 Azure 資源:瞭解如何在 Azure 入口網站 中建立和管理資源群組。
- Azure 部落格:瞭解 Azure 中的新功能。
- Windows PowerShell 部落格:瞭解 Windows PowerShell 中的新功能。
- “嘿,腳本傢伙!部落格:從 Windows PowerShell 社群取得真實世界的秘訣和訣竅。