diff --git a/samples/Foundatio.SampleJob/SampleServiceProvider.cs b/samples/Foundatio.SampleJob/SampleServiceProvider.cs index 6de6b85..8d8ca04 100644 --- a/samples/Foundatio.SampleJob/SampleServiceProvider.cs +++ b/samples/Foundatio.SampleJob/SampleServiceProvider.cs @@ -18,7 +18,7 @@ public static IServiceProvider Create(ILoggerFactory loggerFactory) { container.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); } - var muxer = ConnectionMultiplexer.Connect("localhost"); + var muxer = ConnectionMultiplexer.Connect("localhost", o => o.LoggerFactory = loggerFactory); container.AddSingleton(muxer); container.AddSingleton>(s => new RedisQueue(o => o.ConnectionMultiplexer(muxer).RetryDelay(TimeSpan.FromSeconds(1)).WorkItemTimeout(TimeSpan.FromSeconds(5)).LoggerFactory(loggerFactory))); container.AddSingleton(s => new RedisCacheClient(o => o.ConnectionMultiplexer(muxer).LoggerFactory(loggerFactory))); diff --git a/samples/Foundatio.SampleJobClient/Program.cs b/samples/Foundatio.SampleJobClient/Program.cs index 45b7df2..aa69932 100644 --- a/samples/Foundatio.SampleJobClient/Program.cs +++ b/samples/Foundatio.SampleJobClient/Program.cs @@ -27,7 +27,7 @@ public static void Main(string[] args) _loggerFactory.MaxLogEntriesToStore = Console.WindowHeight - (OPTIONS_MENU_LINE_COUNT + SEPERATOR_LINE_COUNT) - 1; _logger = _loggerFactory.CreateLogger(); - var muxer = ConnectionMultiplexer.Connect("localhost"); + var muxer = ConnectionMultiplexer.Connect("localhost", o => o.LoggerFactory = _loggerFactory); _queue = new RedisQueue(new RedisQueueOptions { ConnectionMultiplexer = muxer }); _messageBus = new RedisMessageBus(o => o.Subscriber(muxer.GetSubscriber()).LoggerFactory(_loggerFactory).MapMessageTypeToClassName()); diff --git a/src/Foundatio.Redis/Cache/RedisCacheClientOptions.cs b/src/Foundatio.Redis/Cache/RedisCacheClientOptions.cs index bd82447..acddc63 100644 --- a/src/Foundatio.Redis/Cache/RedisCacheClientOptions.cs +++ b/src/Foundatio.Redis/Cache/RedisCacheClientOptions.cs @@ -1,6 +1,4 @@ -using System; -using Foundatio.Serializer; -using StackExchange.Redis; +using StackExchange.Redis; namespace Foundatio.Caching { public class RedisCacheClientOptions : SharedOptions { diff --git a/src/Foundatio.Redis/Foundatio.Redis.csproj b/src/Foundatio.Redis/Foundatio.Redis.csproj index 0503829..535bcfa 100644 --- a/src/Foundatio.Redis/Foundatio.Redis.csproj +++ b/src/Foundatio.Redis/Foundatio.Redis.csproj @@ -3,7 +3,7 @@ - + diff --git a/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs b/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs index ee817e8..36bdc5a 100644 --- a/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs +++ b/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs @@ -12,12 +12,12 @@ namespace Foundatio.Redis.Tests.Caching { public class RedisCacheClientTests : CacheClientTestsBase { public RedisCacheClientTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } protected override ICacheClient GetCacheClient(bool shouldThrowOnSerializationError = true) { - return new RedisCacheClient(o => o.ConnectionMultiplexer(SharedConnection.GetMuxer()).LoggerFactory(Log).ShouldThrowOnSerializationError(shouldThrowOnSerializationError)); + return new RedisCacheClient(o => o.ConnectionMultiplexer(SharedConnection.GetMuxer(Log)).LoggerFactory(Log).ShouldThrowOnSerializationError(shouldThrowOnSerializationError)); } [Fact] @@ -131,7 +131,7 @@ public override Task CanManageListsAsync() { [Fact] public async Task CanUpgradeListType() { - var db = SharedConnection.GetMuxer().GetDatabase(); + var db = SharedConnection.GetMuxer(Log).GetDatabase(); var cache = GetCacheClient(); if (cache == null) return; diff --git a/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs b/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs index 1e6a42d..37ff826 100644 --- a/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs +++ b/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs @@ -10,13 +10,13 @@ namespace Foundatio.Redis.Tests.Caching { public class RedisHybridCacheClientTests : HybridCacheClientTests { public RedisHybridCacheClientTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } protected override ICacheClient GetCacheClient(bool shouldThrowOnSerializationError = true) { return new RedisHybridCacheClient(o => o - .ConnectionMultiplexer(SharedConnection.GetMuxer()) + .ConnectionMultiplexer(SharedConnection.GetMuxer(Log)) .LoggerFactory(Log).ShouldThrowOnSerializationError(shouldThrowOnSerializationError), localConfig => localConfig .CloneValues(true) diff --git a/tests/Foundatio.Redis.Tests/Jobs/RedisJobQueueTests.cs b/tests/Foundatio.Redis.Tests/Jobs/RedisJobQueueTests.cs index d637f2e..e5ae549 100644 --- a/tests/Foundatio.Redis.Tests/Jobs/RedisJobQueueTests.cs +++ b/tests/Foundatio.Redis.Tests/Jobs/RedisJobQueueTests.cs @@ -9,13 +9,13 @@ namespace Foundatio.Redis.Tests.Jobs { public class RedisJobQueueTests : JobQueueTestsBase { public RedisJobQueueTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } protected override IQueue GetSampleWorkItemQueue(int retries, TimeSpan retryDelay) { return new RedisQueue(o => o - .ConnectionMultiplexer(SharedConnection.GetMuxer()) + .ConnectionMultiplexer(SharedConnection.GetMuxer(Log)) .Retries(retries) .RetryDelay(retryDelay) .LoggerFactory(Log) diff --git a/tests/Foundatio.Redis.Tests/Locks/RedisLockTests.cs b/tests/Foundatio.Redis.Tests/Locks/RedisLockTests.cs index 5c5cb19..d3ccc48 100644 --- a/tests/Foundatio.Redis.Tests/Locks/RedisLockTests.cs +++ b/tests/Foundatio.Redis.Tests/Locks/RedisLockTests.cs @@ -18,7 +18,7 @@ public class RedisLockTests : LockTestBase, IDisposable { private readonly IMessageBus _messageBus; public RedisLockTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); _cache = new RedisCacheClient(o => o.ConnectionMultiplexer(muxer).LoggerFactory(Log)); _messageBus = new RedisMessageBus(o => o.Subscriber(muxer.GetSubscriber()).Topic("test-lock").LoggerFactory(Log)); @@ -95,7 +95,7 @@ public override Task LockOneAtATimeAsync() { public void Dispose() { _cache.Dispose(); _messageBus.Dispose(); - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } } diff --git a/tests/Foundatio.Redis.Tests/Messaging/RedisMessageBusTests.cs b/tests/Foundatio.Redis.Tests/Messaging/RedisMessageBusTests.cs index 11759aa..9e3083c 100644 --- a/tests/Foundatio.Redis.Tests/Messaging/RedisMessageBusTests.cs +++ b/tests/Foundatio.Redis.Tests/Messaging/RedisMessageBusTests.cs @@ -15,13 +15,13 @@ namespace Foundatio.Redis.Tests.Messaging { public class RedisMessageBusTests : MessageBusTestBase { public RedisMessageBusTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } protected override IMessageBus GetMessageBus(Func config = null) { return new RedisMessageBus(o => { - o.Subscriber(SharedConnection.GetMuxer().GetSubscriber()); + o.Subscriber(SharedConnection.GetMuxer(Log).GetSubscriber()); o.Topic("test-messages"); o.LoggerFactory(Log); if (config != null) @@ -123,7 +123,7 @@ public override void CanDisposeWithNoSubscribersOrPublishers() { [Fact] public async Task CanDisposeCacheAndQueueAndReceiveSubscribedMessages() { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); var messageBus1 = new RedisMessageBus(new RedisMessageBusOptions { Subscriber = muxer.GetSubscriber(), Topic = "test-messages", LoggerFactory = Log }); var cache = new RedisCacheClient(new RedisCacheClientOptions { ConnectionMultiplexer = muxer }); diff --git a/tests/Foundatio.Redis.Tests/Metrics/RedisMetricsTests.cs b/tests/Foundatio.Redis.Tests/Metrics/RedisMetricsTests.cs index 449ae77..423d316 100644 --- a/tests/Foundatio.Redis.Tests/Metrics/RedisMetricsTests.cs +++ b/tests/Foundatio.Redis.Tests/Metrics/RedisMetricsTests.cs @@ -11,13 +11,13 @@ namespace Foundatio.Redis.Tests.Metrics { public class RedisMetricsTests : MetricsClientTestBase, IDisposable { public RedisMetricsTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } #pragma warning disable CS0618 // Type or member is obsolete public override IMetricsClient GetMetricsClient(bool buffered = false) { - return new RedisMetricsClient(o => o.ConnectionMultiplexer(SharedConnection.GetMuxer()).Buffered(buffered).LoggerFactory(Log)); + return new RedisMetricsClient(o => o.ConnectionMultiplexer(SharedConnection.GetMuxer(Log)).Buffered(buffered).LoggerFactory(Log)); } #pragma warning restore CS0618 // Type or member is obsolete @@ -86,7 +86,7 @@ public async Task SendGaugesBufferedAsync() { [Fact] public async Task SendRedisAsync() { - var db = SharedConnection.GetMuxer().GetDatabase(); + var db = SharedConnection.GetMuxer(Log).GetDatabase(); int max = 1000; for (int index = 0; index <= max; index++) { @@ -95,7 +95,7 @@ public async Task SendRedisAsync() { } public void Dispose() { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } } diff --git a/tests/Foundatio.Redis.Tests/Queues/RedisQueueTests.cs b/tests/Foundatio.Redis.Tests/Queues/RedisQueueTests.cs index 01b4af9..63863d8 100644 --- a/tests/Foundatio.Redis.Tests/Queues/RedisQueueTests.cs +++ b/tests/Foundatio.Redis.Tests/Queues/RedisQueueTests.cs @@ -27,14 +27,14 @@ namespace Foundatio.Redis.Tests.Queues { public class RedisQueueTests : QueueTestBase { public RedisQueueTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); while (muxer.CountAllKeysAsync().GetAwaiter().GetResult() != 0) muxer.FlushAllAsync().GetAwaiter().GetResult(); } protected override IQueue GetQueue(int retries = 1, TimeSpan? workItemTimeout = null, TimeSpan? retryDelay = null, int[] retryMultipliers = null, int deadLetterMaxItems = 100, bool runQueueMaintenance = true) { var queue = new RedisQueue(o => o - .ConnectionMultiplexer(SharedConnection.GetMuxer()) + .ConnectionMultiplexer(SharedConnection.GetMuxer(Log)) .Retries(retries) .RetryDelay(retryDelay.GetValueOrDefault(TimeSpan.FromMinutes(1))) .RetryMultipliers(retryMultipliers ?? new[] { 1, 3, 5, 10 }) @@ -155,7 +155,7 @@ public override Task CanUseQueueOptionsAsync() { [RetryFact] public override async Task CanDequeueWithLockingAsync() { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); using var cache = new RedisCacheClient(new RedisCacheClientOptions { ConnectionMultiplexer = muxer, LoggerFactory = Log }); using var messageBus = new RedisMessageBus(new RedisMessageBusOptions { Subscriber = muxer.GetSubscriber(), Topic = "test-queue", LoggerFactory = Log }); var distributedLock = new CacheLockProvider(cache, messageBus, Log); @@ -164,7 +164,7 @@ public override async Task CanDequeueWithLockingAsync() { [Fact] public override async Task CanHaveMultipleQueueInstancesWithLockingAsync() { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); using var cache = new RedisCacheClient(new RedisCacheClientOptions { ConnectionMultiplexer = muxer, LoggerFactory = Log }); using var messageBus = new RedisMessageBus(new RedisMessageBusOptions { Subscriber = muxer.GetSubscriber(), Topic = "test-queue", LoggerFactory = Log }); var distributedLock = new CacheLockProvider(cache, messageBus, Log); @@ -178,7 +178,7 @@ public async Task VerifyCacheKeysAreCorrect() { return; using (queue) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); var db = muxer.GetDatabase(); string listPrefix = muxer.IsCluster() ? "{q:SimpleWorkItem}" : "q:SimpleWorkItem"; @@ -231,7 +231,7 @@ public async Task VerifyCacheKeysAreCorrectAfterAbandon() { using (TestSystemClock.Install()) { using (queue) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); var db = muxer.GetDatabase(); string listPrefix = muxer.IsCluster() ? "{q:SimpleWorkItem}" : "q:SimpleWorkItem"; @@ -299,7 +299,7 @@ public async Task VerifyCacheKeysAreCorrectAfterAbandonWithRetryDelay() { using (TestSystemClock.Install()) { using (queue) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); var db = muxer.GetDatabase(); string listPrefix = muxer.IsCluster() ? "{q:SimpleWorkItem}" : "q:SimpleWorkItem"; @@ -361,7 +361,7 @@ public async Task CanTrimDeadletterItems() { return; using (queue) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); var db = muxer.GetDatabase(); string listPrefix = muxer.IsCluster() ? "{q:SimpleWorkItem}" : "q:SimpleWorkItem"; @@ -552,7 +552,7 @@ await queue.EnqueueAsync(new SimpleWorkItem { Assert.Equal(workItemCount, stats.Completed + stats.Deadletter); Assert.Equal(0, stats.Queued); - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); _logger.LogTrace("# Keys: {0}", muxer.CountAllKeysAsync()); } } @@ -590,7 +590,7 @@ await queue.EnqueueAsync(new SimpleWorkItem { Assert.Equal(workItemCount, stats.Completed); Assert.Equal(0, stats.Queued); - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); _logger.LogTrace("# Keys: {0}", muxer.CountAllKeysAsync()); } } @@ -630,7 +630,7 @@ await queue.StartWorkingAsync(async workItem => { Assert.Equal(workItemCount, stats.Completed); Assert.Equal(0, stats.Queued); - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); _logger.LogTrace("# Keys: {0}", muxer.CountAllKeysAsync()); } } @@ -663,7 +663,7 @@ private IQueue CreateQueue(bool allQueuesTheSameName = true) where T : cla name = "cmd"; var queue = new RedisQueue(o => o - .ConnectionMultiplexer(SharedConnection.GetMuxer()) + .ConnectionMultiplexer(SharedConnection.GetMuxer(Log)) .Name(name) .LoggerFactory(Log) ); diff --git a/tests/Foundatio.Redis.Tests/SharedConnection.cs b/tests/Foundatio.Redis.Tests/SharedConnection.cs index 003eb69..386c8f2 100644 --- a/tests/Foundatio.Redis.Tests/SharedConnection.cs +++ b/tests/Foundatio.Redis.Tests/SharedConnection.cs @@ -1,18 +1,19 @@ using System; using Foundatio.Tests.Utility; +using Microsoft.Extensions.Logging; using StackExchange.Redis; namespace Foundatio.Redis.Tests { public static class SharedConnection { private static ConnectionMultiplexer _muxer; - public static ConnectionMultiplexer GetMuxer() { + public static ConnectionMultiplexer GetMuxer(ILoggerFactory loggerFactory) { string connectionString = Configuration.GetConnectionString("RedisConnectionString"); if (String.IsNullOrEmpty(connectionString)) return null; if (_muxer == null) - _muxer = ConnectionMultiplexer.Connect(connectionString); + _muxer = ConnectionMultiplexer.Connect(connectionString, o => o.LoggerFactory = loggerFactory); return _muxer; } diff --git a/tests/Foundatio.Redis.Tests/Storage/RedisFileStorageTests.cs b/tests/Foundatio.Redis.Tests/Storage/RedisFileStorageTests.cs index a4967bb..d92f922 100644 --- a/tests/Foundatio.Redis.Tests/Storage/RedisFileStorageTests.cs +++ b/tests/Foundatio.Redis.Tests/Storage/RedisFileStorageTests.cs @@ -8,12 +8,12 @@ namespace Foundatio.Redis.Tests.Storage { public class RedisFileStorageTests : FileStorageTestsBase { public RedisFileStorageTests(ITestOutputHelper output) : base(output) { - var muxer = SharedConnection.GetMuxer(); + var muxer = SharedConnection.GetMuxer(Log); muxer.FlushAllAsync().GetAwaiter().GetResult(); } protected override IFileStorage GetStorage() { - return new RedisFileStorage(o => o.ConnectionMultiplexer(SharedConnection.GetMuxer()).LoggerFactory(Log)); + return new RedisFileStorage(o => o.ConnectionMultiplexer(SharedConnection.GetMuxer(Log)).LoggerFactory(Log)); } [Fact]