This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
6-create-redis.ps1
70 lines (59 loc) · 1.99 KB
/
6-create-redis.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Install Azure PowerShell module (needs admin privilege)
Install-Module -Name Az -AllowClobber
# Variables to edit
$YOURSUBSCRIPTIONID='XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
$RESOURCEGROUPNAME='myResourceGroup'
$REGIONNAME='japanwest'
$PREFIX='myGameBackend'
$RANDOMNUMBER=Get-Random
$REDISNAME=$PREFIX+'Redis'
$REDISNAMEUNIQUE=$REDISNAME+$RANDOMNUMBER
$REDISVMSIZE='C1'
$REDISSKU='Standard'
$REDISSHARDSTOCREATE=2
$VNETNAME=$PREFIX+'VNET'
$REDISSUBNETNAME=$REDISNAME+'Subnet'
$REDISSUBNETADDRESSPREFIX='10.0.1.0/24'
$SUBNETID='/subscriptions/'+$YOURSUBSCRIPTIONID+'/resourceGroups/'+$RESOURCEGROUPNAME+'/providers/Microsoft.Network/virtualNetworks/'+$VNETNAME+'/subnets/'+$REDISSUBNETNAME
# Connect to Azure
Connect-AzAccount
# Set the Azure subscription
Set-AzContext `
-SubscriptionId $YOURSUBSCRIPTIONID
# Create a specific subnet named cache
$vnet = Get-AzVirtualNetwork `
-ResourceGroupName $RESOURCEGROUPNAME `
-Name $VNETNAME
$subnetConfig = Add-AzVirtualNetworkSubnetConfig `
-Name $REDISSUBNETNAME `
-AddressPrefix $REDISSUBNETADDRESSPREFIX `
-VirtualNetwork $vnet
$vnet | Set-AzVirtualNetwork
# Create an Azure Cache for Redis
if($REDISSKU -eq "Standard") {
New-AzRedisCache `
-ResourceGroupName $RESOURCEGROUPNAME `
-Name $REDISNAMEUNIQUE `
-Location $REGIONNAME `
-Size $REDISVMSIZE `
-Sku $REDISSKU `
-RedisConfiguration @{"maxmemory-policy" = "allkeys-random"}
}
if($REDISSKU -eq "Premium") {
New-AzRedisCache `
-ResourceGroupName $RESOURCEGROUPNAME `
-Name $REDISNAMEUNIQUE `
-Location $REGIONNAME `
-Size $REDISVMSIZE `
-Sku $REDISSKU `
-RedisConfiguration @{"maxmemory-policy" = "allkeys-random"} `
-ShardCount $REDISSHARDSTOCREATE `
-SubnetId $SUBNETID
}
# Get details of the cache (hostName, enableNonSslPort, port, sslPort, primaryKey and secondaryKey)
Get-AzRedisCache `
-ResourceGroupName $RESOURCEGROUPNAME `
-Name $REDISNAMEUNIQUE | Select-Object HostName, EnableNonSslPort, Port, SslPort
Get-AzRedisCacheKey `
-ResourceGroupName $RESOURCEGROUPNAME `
-Name $REDISNAMEUNIQUE