Skip to content

Commit

Permalink
Merge pull request #241 from cnblogs/use-dnsendpoint
Browse files Browse the repository at this point in the history
refactor: use DnsEndPoint
  • Loading branch information
cnblogs-dudu authored Nov 23, 2024
2 parents 5afe0c6 + 4fa29cf commit 25cae83
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;

namespace Enyim.Caching.Configuration
{
Expand Down Expand Up @@ -208,7 +206,7 @@ public MemcachedClientConfiguration(

private void ConfigureServers(MemcachedClientOptions options)
{
Servers = new List<EndPoint>();
Servers = [];
foreach (var server in options.Servers)
{
if (options.UseSslStream)
Expand All @@ -217,29 +215,16 @@ private void ConfigureServers(MemcachedClientOptions options)
}
else
{
if (!IPAddress.TryParse(server.Address, out var address))
if (IPAddress.TryParse(server.Address, out var address))
{
address = Dns.GetHostAddresses(server.Address)
.FirstOrDefault(i =>
i.AddressFamily == (options.UseIPv6
? AddressFamily.InterNetworkV6
: AddressFamily.InterNetwork));

if (address == null)
{
_logger.LogError($"Could not resolve host '{server.Address}'.");
}
else
{
_logger.LogInformation($"Memcached server address - {address}");
}
Servers.Add(new IPEndPoint(address, server.Port));
}
else
{
_logger.LogInformation($"Memcached server address - {server.Address}:{server.Port}");
AddServer(server.Address, server.Port);
}

Servers.Add(new IPEndPoint(address, server.Port));
_logger.LogInformation("Memcached server address - {address}:{port}", server.Address, server.Port);
}
}
}
Expand Down

0 comments on commit 25cae83

Please sign in to comment.