Skip to content

Commit

Permalink
Fix redis local string
Browse files Browse the repository at this point in the history
  • Loading branch information
Senorsen committed Oct 1, 2017
1 parent 519f5d4 commit 9ff6c68
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Wukong/Helpers/RedisConnectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ public class RedisConnectionUtil
{
public static string RedisConnectionDnsLookup(string redisConnectionString)
{
if (string.IsNullOrEmpty(redisConnectionString)) return null;
ConfigurationOptions config = ConfigurationOptions.Parse(redisConnectionString);
try {
if (string.IsNullOrEmpty(redisConnectionString)) return null;
ConfigurationOptions config = ConfigurationOptions.Parse(redisConnectionString);

DnsEndPoint addressEndpoint = config.EndPoints.First() as DnsEndPoint;
int port = addressEndpoint.Port;
DnsEndPoint addressEndpoint = config.EndPoints.First() as DnsEndPoint;
int port = addressEndpoint.Port;

bool isIp = IsIpAddress(addressEndpoint.Host);
if (!isIp)
{
// Please Don't use this line in blocking context. Please remove ".Result"
// Just for test purposes
IPAddress ip = Dns.GetHostEntryAsync(addressEndpoint.Host).Result.AddressList.Last();
return redisConnectionString.Replace(addressEndpoint.Host, ip.ToString());
bool isIp = IsIpAddress(addressEndpoint.Host);
if (!isIp)
{
// Please Don't use this line in blocking context. Please remove ".Result"
// Just for test purposes
IPAddress ip = Dns.GetHostEntryAsync(addressEndpoint.Host).Result.AddressList.Last();
return redisConnectionString.Replace(addressEndpoint.Host, ip.ToString());
}
else
{
return redisConnectionString;
}
}
else
catch
{
return redisConnectionString;
}
Expand Down

0 comments on commit 9ff6c68

Please sign in to comment.