Skip to content

Commit 30f376d

Browse files
authored
Caching Redis: Add option to register profiling session (#31018)
* Add option to register profiling session * Add API change * Fix public API declaration * Cleanup
1 parent ef0c2fc commit 30f376d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
#nullable enable
2+
~Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ProfilingSession.get -> System.Func<StackExchange.Redis.Profiling.ProfilingSession>
3+
~Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ProfilingSession.set -> void

src/Caching/StackExchangeRedis/src/RedisCache.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ private void Connect()
199199
{
200200
_connection = ConnectionMultiplexer.Connect(_options.Configuration);
201201
}
202+
203+
TryRegisterProfiler();
202204
_cache = _connection.GetDatabase();
203205
}
204206
}
@@ -232,6 +234,7 @@ private void Connect()
232234
_connection = await ConnectionMultiplexer.ConnectAsync(_options.Configuration).ConfigureAwait(false);
233235
}
234236

237+
TryRegisterProfiler();
235238
_cache = _connection.GetDatabase();
236239
}
237240
}
@@ -241,6 +244,14 @@ private void Connect()
241244
}
242245
}
243246

247+
private void TryRegisterProfiler()
248+
{
249+
if (_connection != null && _options.ProfilingSession != null)
250+
{
251+
_connection.RegisterProfiler(_options.ProfilingSession);
252+
}
253+
}
254+
244255
private byte[] GetAndRefresh(string key, bool getData)
245256
{
246257
if (key == null)

src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using Microsoft.Extensions.Options;
67
using StackExchange.Redis;
8+
using StackExchange.Redis.Profiling;
79

810
namespace Microsoft.Extensions.Caching.StackExchangeRedis
911
{
@@ -28,9 +30,14 @@ public class RedisCacheOptions : IOptions<RedisCacheOptions>
2830
/// </summary>
2931
public string InstanceName { get; set; }
3032

33+
/// <summary>
34+
/// The Redis profiling session
35+
/// </summary>
36+
public Func<ProfilingSession> ProfilingSession { get; set; }
37+
3138
RedisCacheOptions IOptions<RedisCacheOptions>.Value
3239
{
3340
get { return this; }
3441
}
3542
}
36-
}
43+
}

0 commit comments

Comments
 (0)