|
|
@ -4,7 +4,6 @@ using Newtonsoft.Json; |
|
|
|
using StackExchange.Redis; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Net; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model |
|
|
@ -16,12 +15,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model |
|
|
|
|
|
|
|
private ConnectionMultiplexer _redis; |
|
|
|
|
|
|
|
|
|
|
|
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
_settings = options.Value; |
|
|
|
_logger = loggerFactory.CreateLogger<RedisBasketRepository>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public async Task<bool> DeleteBasketAsync(string id) |
|
|
@ -93,21 +90,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model |
|
|
|
} |
|
|
|
|
|
|
|
private async Task ConnectToRedisAsync() |
|
|
|
{ |
|
|
|
// TODO: Need to make this more robust. ConnectionMultiplexer.ConnectAsync doesn't like domain names or IPv6 addresses.
|
|
|
|
if (IPAddress.TryParse(_settings.ConnectionString, out var ip)) |
|
|
|
{ |
|
|
|
_redis = await ConnectionMultiplexer.ConnectAsync(ip.ToString()); |
|
|
|
_logger.LogInformation($"Connecting to database at {_settings.ConnectionString}"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// workaround for https://github.com/StackExchange/StackExchange.Redis/issues/410
|
|
|
|
var ips = await Dns.GetHostAddressesAsync(_settings.ConnectionString); |
|
|
|
_logger.LogInformation($"Connecting to database {_settings.ConnectionString} at IP {ips.First().ToString()}"); |
|
|
|
_redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString()); |
|
|
|
} |
|
|
|
{ |
|
|
|
var configuration = ConfigurationOptions.Parse(_settings.ConnectionString, true); |
|
|
|
configuration.ResolveDns = true; |
|
|
|
|
|
|
|
_logger.LogInformation($"Connecting to database {configuration.SslHost}."); |
|
|
|
_redis = await ConnectionMultiplexer.ConnectAsync(configuration); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |