Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Caching/StackExchangeRedis/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
~Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ProfilingSession.get -> System.Func<StackExchange.Redis.Profiling.ProfilingSession>
~Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ProfilingSession.set -> void
11 changes: 11 additions & 0 deletions src/Caching/StackExchangeRedis/src/RedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ private void Connect()
{
_connection = ConnectionMultiplexer.Connect(_options.Configuration);
}

TryRegisterProfiler();
_cache = _connection.GetDatabase();
}
}
Expand Down Expand Up @@ -232,6 +234,7 @@ private void Connect()
_connection = await ConnectionMultiplexer.ConnectAsync(_options.Configuration).ConfigureAwait(false);
}

TryRegisterProfiler();
_cache = _connection.GetDatabase();
}
}
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -28,9 +30,14 @@ public class RedisCacheOptions : IOptions<RedisCacheOptions>
/// </summary>
public string InstanceName { get; set; }

/// <summary>
/// The Redis profiling session
/// </summary>
public Func<ProfilingSession> ProfilingSession { get; set; }

RedisCacheOptions IOptions<RedisCacheOptions>.Value
{
get { return this; }
}
}
}
}