@@ -33,7 +33,7 @@ public class RedisCache : IDistributedCache, IDisposable
3333 private const string DataKey = "data" ;
3434 private const long NotPresent = - 1 ;
3535
36- private volatile ConnectionMultiplexer _connection ;
36+ private volatile IConnectionMultiplexer _connection ;
3737 private IDatabase _cache ;
3838 private bool _disposed ;
3939
@@ -190,13 +190,20 @@ private void Connect()
190190 {
191191 if ( _cache == null )
192192 {
193- if ( _options . ConfigurationOptions ! = null )
193+ if ( _options . ConnectionMultiplexerFactory = = null )
194194 {
195- _connection = ConnectionMultiplexer . Connect ( _options . ConfigurationOptions ) ;
195+ if ( _options . ConfigurationOptions is not null )
196+ {
197+ _connection = ConnectionMultiplexer . Connect ( _options . ConfigurationOptions ) ;
198+ }
199+ else
200+ {
201+ _connection = ConnectionMultiplexer . Connect ( _options . Configuration ) ;
202+ }
196203 }
197204 else
198205 {
199- _connection = ConnectionMultiplexer . Connect ( _options . Configuration ) ;
206+ _connection = _options . ConnectionMultiplexerFactory ( ) . GetAwaiter ( ) . GetResult ( ) ;
200207 }
201208
202209 TryRegisterProfiler ( ) ;
@@ -224,13 +231,20 @@ private void Connect()
224231 {
225232 if ( _cache == null )
226233 {
227- if ( _options . ConfigurationOptions != null )
234+ if ( _options . ConnectionMultiplexerFactory is null )
228235 {
229- _connection = await ConnectionMultiplexer . ConnectAsync ( _options . ConfigurationOptions ) . ConfigureAwait ( false ) ;
236+ if ( _options . ConfigurationOptions is not null )
237+ {
238+ _connection = await ConnectionMultiplexer . ConnectAsync ( _options . ConfigurationOptions ) . ConfigureAwait ( false ) ;
239+ }
240+ else
241+ {
242+ _connection = await ConnectionMultiplexer . ConnectAsync ( _options . Configuration ) . ConfigureAwait ( false ) ;
243+ }
230244 }
231245 else
232246 {
233- _connection = await ConnectionMultiplexer . ConnectAsync ( _options . Configuration ) . ConfigureAwait ( false ) ;
247+ _connection = await _options . ConnectionMultiplexerFactory ( ) ;
234248 }
235249
236250 TryRegisterProfiler ( ) ;
@@ -449,7 +463,7 @@ private void Refresh(string key, DateTimeOffset? absExpr, TimeSpan? sldExpr)
449463 options . AbsoluteExpiration . Value ,
450464 "The absolute expiration value must be in the future." ) ;
451465 }
452-
466+
453467 if ( options . AbsoluteExpirationRelativeToNow . HasValue )
454468 {
455469 return creationTime + options . AbsoluteExpirationRelativeToNow ;
0 commit comments