@@ -33,7 +33,7 @@ public class RedisCache : IDistributedCache, IDisposable
33
33
private const string DataKey = "data" ;
34
34
private const long NotPresent = - 1 ;
35
35
36
- private volatile ConnectionMultiplexer _connection ;
36
+ private volatile IConnectionMultiplexer _connection ;
37
37
private IDatabase _cache ;
38
38
private bool _disposed ;
39
39
@@ -190,13 +190,20 @@ private void Connect()
190
190
{
191
191
if ( _cache == null )
192
192
{
193
- if ( _options . ConfigurationOptions ! = null )
193
+ if ( _options . ConnectionMultiplexerFactory = = null )
194
194
{
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
+ }
196
203
}
197
204
else
198
205
{
199
- _connection = ConnectionMultiplexer . Connect ( _options . Configuration ) ;
206
+ _connection = _options . ConnectionMultiplexerFactory ( ) . GetAwaiter ( ) . GetResult ( ) ;
200
207
}
201
208
202
209
TryRegisterProfiler ( ) ;
@@ -224,13 +231,20 @@ private void Connect()
224
231
{
225
232
if ( _cache == null )
226
233
{
227
- if ( _options . ConfigurationOptions != null )
234
+ if ( _options . ConnectionMultiplexerFactory is null )
228
235
{
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
+ }
230
244
}
231
245
else
232
246
{
233
- _connection = await ConnectionMultiplexer . ConnectAsync ( _options . Configuration ) . ConfigureAwait ( false ) ;
247
+ _connection = await _options . ConnectionMultiplexerFactory ( ) ;
234
248
}
235
249
236
250
TryRegisterProfiler ( ) ;
@@ -449,7 +463,7 @@ private void Refresh(string key, DateTimeOffset? absExpr, TimeSpan? sldExpr)
449
463
options . AbsoluteExpiration . Value ,
450
464
"The absolute expiration value must be in the future." ) ;
451
465
}
452
-
466
+
453
467
if ( options . AbsoluteExpirationRelativeToNow . HasValue )
454
468
{
455
469
return creationTime + options . AbsoluteExpirationRelativeToNow ;
0 commit comments