File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
src/EasyCaching.Redis/Configurations
test/EasyCaching.UnitTests/CachingTests Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 11namespace EasyCaching . Redis
22{
33 using EasyCaching . Core . Configurations ;
4+ using StackExchange . Redis ;
45
56 /// <summary>
67 /// Redis cache options.
@@ -29,5 +30,10 @@ public class RedisDBOptions : BaseRedisOptions
2930 /// Gets or sets the Redis database KeyPrefix will use.
3031 /// </summary>
3132 public string KeyPrefix { get ; set ; }
33+
34+ /// <summary>
35+ /// Gets or sets the Redis database ConfigurationOptions will use.
36+ /// </summary>
37+ public ConfigurationOptions ConfigurationOptions { get ; set ; }
3238 }
3339}
Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ public IEnumerable<IServer> GetServerList()
7373 /// <returns>The connection multiplexer.</returns>
7474 private ConnectionMultiplexer CreateConnectionMultiplexer ( )
7575 {
76+ if ( _options . ConfigurationOptions != null )
77+ return ConnectionMultiplexer . Connect ( _options . ConfigurationOptions . ToString ( ) ) ;
78+
7679 if ( string . IsNullOrWhiteSpace ( _options . Configuration ) )
7780 {
7881 var configurationOptions = new ConfigurationOptions
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ namespace EasyCaching.UnitTests
88 using EasyCaching . Serialization . Json ;
99 using EasyCaching . Serialization . MessagePack ;
1010 using Microsoft . Extensions . DependencyInjection ;
11+ using StackExchange . Redis ;
1112 using System ;
1213 using Xunit ;
1314
@@ -98,6 +99,24 @@ public void Use_Configuration_String_Should_Succeed()
9899 Assert . Equal ( 8 , dbProvider . GetDatabase ( ) . Database ) ;
99100 }
100101
102+ [ Fact ]
103+ public void Use_Configuration_Options_Should_Succeed ( )
104+ {
105+ IServiceCollection services = new ServiceCollection ( ) ;
106+ var redisConfig = ConfigurationOptions . Parse ( "127.0.0.1:6380" ) ;
107+ redisConfig . DefaultDatabase = 8 ;
108+ services . AddEasyCaching ( x =>
109+ x . UseRedis ( options =>
110+ {
111+ options . DBConfig . ConfigurationOptions = redisConfig ;
112+ } , ProviderName ) . UseRedisLock ( ) . WithJson ( ProviderName ) ) ;
113+ IServiceProvider serviceProvider = services . BuildServiceProvider ( ) ;
114+ var dbProvider = serviceProvider . GetService < IRedisDatabaseProvider > ( ) ;
115+ Assert . NotNull ( dbProvider ) ;
116+
117+ Assert . Equal ( 8 , dbProvider . GetDatabase ( ) . Database ) ;
118+ }
119+
101120 [ Fact ]
102121 public void GetDatabase_Should_Succeed ( )
103122 {
You can’t perform that action at this time.
0 commit comments