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 1
1
namespace EasyCaching . Redis
2
2
{
3
3
using EasyCaching . Core . Configurations ;
4
+ using StackExchange . Redis ;
4
5
5
6
/// <summary>
6
7
/// Redis cache options.
@@ -29,5 +30,10 @@ public class RedisDBOptions : BaseRedisOptions
29
30
/// Gets or sets the Redis database KeyPrefix will use.
30
31
/// </summary>
31
32
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 ; }
32
38
}
33
39
}
Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ public IEnumerable<IServer> GetServerList()
73
73
/// <returns>The connection multiplexer.</returns>
74
74
private ConnectionMultiplexer CreateConnectionMultiplexer ( )
75
75
{
76
+ if ( _options . ConfigurationOptions != null )
77
+ return ConnectionMultiplexer . Connect ( _options . ConfigurationOptions . ToString ( ) ) ;
78
+
76
79
if ( string . IsNullOrWhiteSpace ( _options . Configuration ) )
77
80
{
78
81
var configurationOptions = new ConfigurationOptions
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ namespace EasyCaching.UnitTests
8
8
using EasyCaching . Serialization . Json ;
9
9
using EasyCaching . Serialization . MessagePack ;
10
10
using Microsoft . Extensions . DependencyInjection ;
11
+ using StackExchange . Redis ;
11
12
using System ;
12
13
using Xunit ;
13
14
@@ -98,6 +99,24 @@ public void Use_Configuration_String_Should_Succeed()
98
99
Assert . Equal ( 8 , dbProvider . GetDatabase ( ) . Database ) ;
99
100
}
100
101
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
+
101
120
[ Fact ]
102
121
public void GetDatabase_Should_Succeed ( )
103
122
{
You can’t perform that action at this time.
0 commit comments