diff --git a/src/Caching/StackExchangeRedis/src/PublicAPI.Unshipped.txt b/src/Caching/StackExchangeRedis/src/PublicAPI.Unshipped.txt index 7dc5c58110bf..93b5d12522b9 100644 --- a/src/Caching/StackExchangeRedis/src/PublicAPI.Unshipped.txt +++ b/src/Caching/StackExchangeRedis/src/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +~Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ProfilingSession.get -> System.Func +~Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ProfilingSession.set -> void diff --git a/src/Caching/StackExchangeRedis/src/RedisCache.cs b/src/Caching/StackExchangeRedis/src/RedisCache.cs index 9604174de237..1e7099209bcd 100644 --- a/src/Caching/StackExchangeRedis/src/RedisCache.cs +++ b/src/Caching/StackExchangeRedis/src/RedisCache.cs @@ -199,6 +199,8 @@ private void Connect() { _connection = ConnectionMultiplexer.Connect(_options.Configuration); } + + TryRegisterProfiler(); _cache = _connection.GetDatabase(); } } @@ -232,6 +234,7 @@ private void Connect() _connection = await ConnectionMultiplexer.ConnectAsync(_options.Configuration).ConfigureAwait(false); } + TryRegisterProfiler(); _cache = _connection.GetDatabase(); } } @@ -241,6 +244,14 @@ private void Connect() } } + private void TryRegisterProfiler() + { + if (_connection != null && _options.ProfilingSession != null) + { + _connection.RegisterProfiler(_options.ProfilingSession); + } + } + private byte[] GetAndRefresh(string key, bool getData) { if (key == null) diff --git a/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs b/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs index eb38b92eae31..5bba6f3ddbcd 100644 --- a/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs +++ b/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using Microsoft.Extensions.Options; using StackExchange.Redis; +using StackExchange.Redis.Profiling; namespace Microsoft.Extensions.Caching.StackExchangeRedis { @@ -28,9 +30,14 @@ public class RedisCacheOptions : IOptions /// public string InstanceName { get; set; } + /// + /// The Redis profiling session + /// + public Func ProfilingSession { get; set; } + RedisCacheOptions IOptions.Value { get { return this; } } } -} \ No newline at end of file +}