-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathAzureOptionsProvider.cs
More file actions
88 lines (79 loc) · 2.75 KB
/
AzureOptionsProvider.cs
File metadata and controls
88 lines (79 loc) · 2.75 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Net;
using System.Threading.Tasks;
using StackExchange.Redis.Maintenance;
namespace StackExchange.Redis.Configuration
{
/// <summary>
/// Options provider for Azure environments.
/// </summary>
public class AzureOptionsProvider : DefaultOptionsProvider
{
/// <summary>
/// Allow connecting after startup, in the cases where remote cache isn't ready or is overloaded.
/// </summary>
public override bool AbortOnConnectFail => false;
/// <summary>
/// The minimum version of Redis in Azure is 6, so use the widest set of available commands when connecting.
/// </summary>
public override Version DefaultVersion => RedisFeatures.v6_0_0;
/// <summary>
/// Lists of domains known to be Azure Redis, so we can light up some helpful functionality
/// for minimizing downtime during maintenance events and such.
/// </summary>
private static readonly string[] azureRedisDomains = new[]
{
".redis.cache.windows.net",
".redis.cache.chinacloudapi.cn",
".redis.cache.usgovcloudapi.net",
".redis.cache.sovcloud-api.de",
".redis.cache.sovcloud-api.fr",
};
/// <inheritdoc/>
public override bool IsMatch(EndPoint endpoint)
{
if (endpoint is DnsEndPoint dnsEp && IsHostInDomains(dnsEp.Host, azureRedisDomains))
{
return true;
}
return false;
}
private bool IsHostInDomains(string hostName, string[] domains)
{
foreach (var domain in domains)
{
if (hostName.EndsWith(domain, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
}
return false;
}
/// <inheritdoc/>
public override Task AfterConnectAsync(ConnectionMultiplexer muxer, Action<string> log)
=> AzureMaintenanceEvent.AddListenerAsync(muxer, log);
/// <inheritdoc/>
public override bool GetDefaultSsl(EndPointCollection endPoints)
{
foreach (var ep in endPoints)
{
switch (ep)
{
case DnsEndPoint dns:
if (dns.Port == 6380)
{
return true;
}
break;
case IPEndPoint ip:
if (ip.Port == 6380)
{
return true;
}
break;
}
}
return false;
}
}
}