Skip to content

Commit

Permalink
Allow reuse of a Redis ConnectionMultiplexer instance between RedisCa…
Browse files Browse the repository at this point in the history
…che and RedisBackplane (#177)

Added a factory method (ConnectionMultiplexerFactory) to RedisBackplaneOptions to allow passing a ConnectionMultiplexer instance.
  • Loading branch information
JeffreyM authored Oct 14, 2023
1 parent 2b80b41 commit eaa8e09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using StackExchange.Redis;

namespace ZiggyCreatures.Caching.Fusion.Backplane.StackExchangeRedis;
Expand All @@ -20,6 +22,11 @@ public class RedisBackplaneOptions
/// </summary>
public ConfigurationOptions? ConfigurationOptions { get; set; }

/// <summary>
/// Gets or sets a delegate to create the ConnectionMultiplexer instance.
/// </summary>
public Func<Task<IConnectionMultiplexer>>? ConnectionMultiplexerFactory { get; set; }

/// <summary>
/// The configuration used to connect to Redis.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ private void EnsureConnection(CancellationToken token = default)
if (_connection is not null)
return;

_connection = ConnectionMultiplexer.Connect(GetConfigurationOptions());
_connection = _options.ConnectionMultiplexerFactory is null
? ConnectionMultiplexer.Connect(GetConfigurationOptions())
: _options.ConnectionMultiplexerFactory().GetAwaiter().GetResult();

if (_connection is not null)
{
_connection.ConnectionRestored += OnReconnect;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eaa8e09

Please sign in to comment.