Skip to content

[Redis] New Param added to choose redis version #15549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/RedisCache/RedisCache.Test/RedisCache.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Insights" Version="0.16.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RedisCache\RedisCache.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Test-RedisCache
New-AzResourceGroup -Name $resourceGroupName -Location $location

# Creating Cache
$cacheCreated = New-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -Location $location -Size P1 -Sku Premium
$cacheCreated = New-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -Location $location -Size P1 -Sku Premium -RedisVersion 6

Assert-AreEqual $cacheName $cacheCreated.Name
Assert-AreEqual $location $cacheCreated.Location
Expand All @@ -25,6 +25,7 @@ function Test-RedisCache
Assert-AreEqual "creating" $cacheCreated.ProvisioningState
Assert-AreEqual "6GB" $cacheCreated.Size
Assert-AreEqual "Premium" $cacheCreated.Sku
Assert-AreEqual "6" $cacheCreated.RedisVersion.split(".")[0]

Assert-NotNull $cacheCreated.PrimaryKey "PrimaryKey do not exists"
Assert-NotNull $cacheCreated.SecondaryKey "SecondaryKey do not exists"
Expand Down Expand Up @@ -171,7 +172,7 @@ function Test-RedisCachePipeline
}

# Updating Cache using pipeline
Get-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName | Set-AzRedisCache -RedisConfiguration @{"maxmemory-policy" = "allkeys-random"} -EnableNonSslPort $false
Get-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName | Set-AzRedisCache -RedisConfiguration @{"maxmemory-policy" = "allkeys-random"} -EnableNonSslPort $false -RedisVersion 6
$cacheUpdatedPiped = Get-AzRedisCache -Name $cacheName

Assert-AreEqual $cacheName $cacheUpdatedPiped.Name
Expand Down Expand Up @@ -396,7 +397,7 @@ function Test-RedisCachePatchSchedules

Remove-AzRedisCachePatchSchedule -ResourceGroupName $resourceGroupName -Name $cacheName

Assert-ThrowsContains {Get-AzRedisCachePatchSchedule -ResourceGroupName $resourceGroupName -Name $cacheName} "There are no patch schedules found for redis cache"
Assert-ThrowsContains {Get-AzRedisCachePatchSchedule -ResourceGroupName $resourceGroupName -Name $cacheName} "Operation returned an invalid status code 'NotFound'"

############################# Bug fix in set redis cache related to EnableNonSslPort ##########################################
$cacheUpdated = Set-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -EnableNonSslPort $true
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/RedisCache/RedisCache/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Added `RedisVersion` parameter in `New-AzRedisCache` and `Set-AzRedisCache`

## Version 1.4.0
* Made `New-AzRedisCache` and `Set-AzRedisCache` cmdlets not fail because of permission issue related to registering Microsoft.Cache RP
Expand Down
21 changes: 20 additions & 1 deletion src/RedisCache/RedisCache/Commands/NewAzureRedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class NewAzureRedisCache : RedisCacheCmdletBase
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "List of zones.")]
public string[] Zone { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "Redis version. Valid values: 4, 6")]
public string RedisVersion { get; set; }

public override void ExecuteCmdlet()
{
Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
Expand Down Expand Up @@ -133,14 +136,30 @@ public override void ExecuteCmdlet()
throw;
}
}
catch (ErrorResponseException ex)
{
if (ex.Body.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
{
// cache does not exists so go ahead and create one
}
else if (ex.Body.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
{
// resource group not found, let create throw error don't throw from here
}
else
{
// all other exceptions should be thrown
throw;
}
}

ConfirmAction(
string.Format(Resources.CreateRedisCache, Name),
Name,
() =>
{
var redisResource = CacheClient.CreateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku,
RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, MinimumTlsVersion, SubnetId, StaticIP, Tag, Zone);
RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, MinimumTlsVersion, SubnetId, StaticIP, Tag, Zone, RedisVersion);
var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
});
Expand Down
5 changes: 4 additions & 1 deletion src/RedisCache/RedisCache/Commands/SetAzureRedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class SetAzureRedisCache : RedisCacheCmdletBase
[PSArgumentCompleter(TlsStrings.OneFullStopZero, TlsStrings.OneFullStopOne, TlsStrings.OneFullStopTwo)]
public string MinimumTlsVersion { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "Redis version. Valid values: 4, 6")]
public string RedisVersion { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "A hash table which represents tags.")]
public Hashtable Tag { get; set; }

Expand Down Expand Up @@ -116,7 +119,7 @@ public override void ExecuteCmdlet()
() =>
{
var redisResource = CacheClient.UpdateCache(ResourceGroupName, Name, skuFamily, skuCapacity,
skuName, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, MinimumTlsVersion, Tag);
skuName, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, MinimumTlsVersion, RedisVersion, Tag);
var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
});
Expand Down
17 changes: 10 additions & 7 deletions src/RedisCache/RedisCache/Models/RedisCacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public RedisCacheClient(IAzureContext context)
public RedisCacheClient() { }

public RedisResource CreateCache(string resourceGroupName, string cacheName, string location, string skuFamily, int skuCapacity, string skuName,
Hashtable redisConfiguration, bool? enableNonSslPort, Hashtable tenantSettings, int? shardCount, string minimumTlsVersion, string subnetId, string staticIP, Hashtable tags, IList<string> zones)
Hashtable redisConfiguration, bool? enableNonSslPort, Hashtable tenantSettings, int? shardCount, string minimumTlsVersion, string subnetId,
string staticIP, Hashtable tags, IList<string> zones, String redisVersion)
{
try
{
Expand All @@ -63,7 +64,8 @@ public RedisResource CreateCache(string resourceGroupName, string cacheName, str
Name = skuName,
Family = skuFamily,
Capacity = skuCapacity
}
},
RedisVersion = redisVersion
};

if (zones != null && zones.Count != 0)
Expand Down Expand Up @@ -128,7 +130,7 @@ public RedisResource CreateCache(string resourceGroupName, string cacheName, str
}

public RedisResource UpdateCache(string resourceGroupName, string cacheName, string skuFamily, int skuCapacity, string skuName,
Hashtable redisConfiguration, bool? enableNonSslPort, Hashtable tenantSettings, int? shardCount, string MinimumTlsVersion, Hashtable tags)
Hashtable redisConfiguration, bool? enableNonSslPort, Hashtable tenantSettings, int? shardCount, string MinimumTlsVersion, string redisVersion, Hashtable tags)
{
try
{
Expand Down Expand Up @@ -166,6 +168,7 @@ public RedisResource UpdateCache(string resourceGroupName, string cacheName, str
}

parameters.EnableNonSslPort = enableNonSslPort;
parameters.RedisVersion = redisVersion;

if (tenantSettings != null)
{
Expand Down Expand Up @@ -230,7 +233,7 @@ public IPage<RedisResource> ListCaches(string resourceGroupName)
{
if (string.IsNullOrEmpty(resourceGroupName))
{
return _client.Redis.List();
return _client.Redis.ListBySubscription();
}
else
{
Expand All @@ -242,7 +245,7 @@ public IPage<RedisResource> ListCachesUsingNextLink(string resourceGroupName, st
{
if (string.IsNullOrEmpty(resourceGroupName))
{
return _client.Redis.ListNext(nextPageLink: nextLink);
return _client.Redis.ListBySubscriptionNext(nextPageLink: nextLink);
}
else
{
Expand Down Expand Up @@ -339,12 +342,12 @@ internal RedisFirewallRule GetFirewallRule(string resourceGroupName, string cach

internal IPage<RedisFirewallRule> ListFirewallRules(string resourceGroupName, string cacheName)
{
return _client.FirewallRules.ListByRedisResource(resourceGroupName, cacheName);
return _client.FirewallRules.List(resourceGroupName, cacheName);
}

internal IPage<RedisFirewallRule> ListFirewallRules(string nextLink)
{
return _client.FirewallRules.ListByRedisResourceNext(nextLink);
return _client.FirewallRules.ListNext(nextLink);
}

internal void RemoveFirewallRule(string resourceGroupName, string cacheName, string ruleName)
Expand Down
4 changes: 2 additions & 2 deletions src/RedisCache/RedisCache/RedisCache.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>RedisCache</PsModuleName>
Expand All @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Insights" Version="0.16.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="7.0.0" />
</ItemGroup>

</Project>
19 changes: 17 additions & 2 deletions src/RedisCache/RedisCache/help/New-AzRedisCache.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Creates a Redis Cache.
New-AzRedisCache -ResourceGroupName <String> -Name <String> -Location <String> [-Size <String>] [-Sku <String>]
[-RedisConfiguration <Hashtable>] [-EnableNonSslPort <Boolean>] [-TenantSettings <Hashtable>]
[-ShardCount <Int32>] [-MinimumTlsVersion <String>] [-SubnetId <String>] [-StaticIP <String>]
[-Tag <Hashtable>] [-Zone <String[]>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-Tag <Hashtable>] [-Zone <String[]>] [-RedisVersion <String>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -226,6 +226,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -RedisVersion
Redis version. Valid values: 4, 6

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -ResourceGroupName
Specifies the name of the resource group in which to create the Redis Cache.

Expand Down
17 changes: 16 additions & 1 deletion src/RedisCache/RedisCache/help/Set-AzRedisCache.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Modifies a Redis Cache.
```
Set-AzRedisCache [-ResourceGroupName <String>] -Name <String> [-Size <String>] [-Sku <String>]
[-RedisConfiguration <Hashtable>] [-EnableNonSslPort <Boolean>] [-TenantSettings <Hashtable>]
[-ShardCount <Int32>] [-MinimumTlsVersion <String>] [-Tag <Hashtable>]
[-ShardCount <Int32>] [-MinimumTlsVersion <String>] [-RedisVersion <String>] [-Tag <Hashtable>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand Down Expand Up @@ -168,6 +168,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -RedisVersion
Redis version. Valid values: 4, 6

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -ResourceGroupName
Specifies the name of the resource group that contains the Redis Cache.

Expand Down