Skip to content

Commit 006cfaf

Browse files
authored
Recognize Azure Managed Redis in new clouds (#3068)
* Recognize Azure Managed Redis in new clouds
1 parent 2b592a9 commit 006cfaf

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Current package versions:
1212
- Add Redis 8.8 stream negative acknowledgements (`XNACK`) ([#3058 by @mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/3058))
1313
- Update experimental `GCRA` APIs and wire protocol terminology from "requests" to "tokens", to match server change ([#3051 by @mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/3051))
1414
- Add experimental `Aggregate.Count` support for sorted-set combination operations against Redis 8.8 ([#3059 by @mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/3059))
15+
- Recognize Azure Managed Redis (AMR) resources in new Azure clouds ([#3068 by @philon-msft](https://github.com/StackExchange/StackExchange.Redis/pull/3068))
1516

1617
## 2.12.14
1718

src/StackExchange.Redis/Configuration/AzureManagedRedisOptionsProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class AzureManagedRedisOptionsProvider : DefaultOptionsProvider
2525
".redis.azure.net",
2626
".redis.chinacloudapi.cn",
2727
".redis.usgovcloudapi.net",
28+
".redis.sovcloud-api.de",
29+
".redis.sovcloud-api.fr",
2830
".redisenterprise.cache.azure.net",
2931
];
3032

tests/StackExchange.Redis.Tests/ConfigTests.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public void SslProtocols_InvalidValue()
135135
[InlineData("contoso.redis.cache.usgovcloudapi.net:6380", true)]
136136
[InlineData("contoso.redis.cache.sovcloud-api.de:6380", true)]
137137
[InlineData("contoso.redis.cache.sovcloud-api.fr:6380", true)]
138+
[InlineData("contoso.redis.cache.windows.net:6379", false)] // non-SSL port
139+
[InlineData("contoso.redis.cache.windows.net:10000", false)] // wrong port
140+
[InlineData("contoso.redis.cache.windows.net", false)] // no port
138141
public void ConfigurationOptionsDefaultForAzure(string hostAndPort, bool sslShouldBeEnabled)
139142
{
140143
Version defaultAzureVersion = new(6, 0, 0);
@@ -149,11 +152,16 @@ public void ConfigurationOptionsDefaultForAzure(string hostAndPort, bool sslShou
149152
[InlineData("contoso.redis.chinacloudapi.cn:10000", true)]
150153
[InlineData("contoso.redis.usgovcloudapi.net:10000", true)]
151154
[InlineData("contoso.redisenterprise.cache.azure.net:10000", true)]
155+
[InlineData("contoso.REDIS.sovcloud-api.de:10000", true)] // added a few upper case chars to validate comparison
156+
[InlineData("contoso.redis.sovcloud-api.fr:10000", true)]
157+
[InlineData("contoso.redis.azure.net:6379", true)] // AMR port is usually 10000, assume SSL regardless
158+
[InlineData("contoso.redis.azure.net:6380", true)] // AMR port is usually 10000, assume SSL regardless
159+
[InlineData("contoso.redis.azure.net", true)] // no port, assume SSL
152160
public void ConfigurationOptionsDefaultForAzureManagedRedis(string hostAndPort, bool sslShouldBeEnabled)
153161
{
154-
Version defaultAzureVersion = new(7, 4, 0);
162+
Version defaultAzureManagedRedisVersion = new(7, 4, 0);
155163
var options = ConfigurationOptions.Parse(hostAndPort);
156-
Assert.True(options.DefaultVersion.Equals(defaultAzureVersion));
164+
Assert.True(options.DefaultVersion.Equals(defaultAzureManagedRedisVersion));
157165
Assert.False(options.AbortOnConnectFail);
158166
Assert.Equal(sslShouldBeEnabled, options.Ssl);
159167
}
@@ -166,12 +174,26 @@ public void ConfigurationOptionsForAzureWhenSpecified()
166174
Assert.True(options.AbortOnConnectFail);
167175
}
168176

169-
[Fact]
170-
public void ConfigurationOptionsDefaultForNonAzure()
177+
[Theory]
178+
[InlineData("redis.contoso.com")] // no port
179+
[InlineData("redis.contoso.com:xx")] // invalid port
180+
[InlineData("redis.contoso.com:6379")] // valid port
181+
[InlineData("contoso.Xredis.cache.windows.net:6380")] // almost an Azure Cache for Redis host name
182+
[InlineData("contoso.redis.cache.windows.netX:6380")] // almost an Azure Cache for Redis host name
183+
[InlineData("contoso.redis.cache.windows.net.X:6380")] // almost an Azure Cache for Redis host name
184+
[InlineData("contoso.Xredis.azure.net:10000")] // almost an Azure Managed Redis host name
185+
[InlineData("contoso.redis.azure.netX:10000")] // almost an Azure Managed Redis host name
186+
[InlineData("contoso.redis.azure.net.X:10000")] // almost an Azure Managed Redis host name
187+
[InlineData("contoso.redis.cache.windows.net:xx")] // Azure Cache for Redis host name with invalid port
188+
[InlineData("contoso.redis.cache.windows.net:")] // Azure Cache for Redis host name with missing port
189+
[InlineData("contoso.redis.azure.net:xx")] // AMR host name with invalid port
190+
[InlineData("contoso.redis.azure.net:")] // AMR host name with missing port
191+
public void ConfigurationOptionsDefaultForNonAzure(string hostAndPort)
171192
{
172-
var options = ConfigurationOptions.Parse("redis.contoso.com");
193+
var options = ConfigurationOptions.Parse(hostAndPort);
173194
Assert.True(options.DefaultVersion.Equals(DefaultVersion));
174195
Assert.True(options.AbortOnConnectFail);
196+
Assert.False(options.Ssl);
175197
}
176198

177199
[Fact]

0 commit comments

Comments
 (0)