This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-9
lines changed
tests/ServiceStack.Redis.Tests Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,18 @@ public IRedisClientsManager Setup()
4949 return this . redisManager ;
5050 }
5151
52+ public Func < string , string > HostFilter { get ; set ; }
53+
54+ internal string [ ] ConfigureHosts ( IEnumerable < string > hosts )
55+ {
56+ if ( hosts == null )
57+ return new string [ 0 ] ;
58+
59+ return HostFilter == null
60+ ? hosts . ToArray ( )
61+ : hosts . Map ( HostFilter ) . ToArray ( ) ;
62+ }
63+
5264 private void GetValidSentinel ( )
5365 {
5466 while ( this . redisManager == null && ShouldRetry ( ) )
Original file line number Diff line number Diff line change @@ -82,11 +82,15 @@ private void ConfigureRedisFromSentinel()
8282
8383 if ( redisManager == null )
8484 {
85- redisManager = redisSentinel . RedisManagerFactory . Create ( masters , slaves ) ;
85+ redisManager = redisSentinel . RedisManagerFactory . Create (
86+ redisSentinel . ConfigureHosts ( masters ) ,
87+ redisSentinel . ConfigureHosts ( slaves ) ) ;
8688 }
8789 else
8890 {
89- ( ( IRedisFailover ) redisManager ) . FailoverTo ( masters , slaves ) ;
91+ ( ( IRedisFailover ) redisManager ) . FailoverTo (
92+ redisSentinel . ConfigureHosts ( masters ) ,
93+ redisSentinel . ConfigureHosts ( slaves ) ) ;
9094 }
9195 }
9296
Original file line number Diff line number Diff line change @@ -101,13 +101,9 @@ public void Can_specify_Timeout_on_RedisManager()
101101 [ Test ]
102102 public void Can_specify_db_on_RedisSentinel ( )
103103 {
104- var host = new [ ] { "{0}:{1}" . Fmt ( TestConfig . SentinelHost , TestConfig . RedisSentinelPort ) } ;
105- var sentinel = new RedisSentinel ( host , TestConfig . MasterName ) {
106- RedisManagerFactory =
107- {
108- FactoryFn = ( writeHosts , readHosts ) =>
109- new PooledRedisClientManager ( writeHosts , readHosts , initalDb : 1 )
110- }
104+ var sentinelHosts = new [ ] { "{0}:{1}" . Fmt ( TestConfig . SentinelHost , TestConfig . RedisSentinelPort ) } ;
105+ var sentinel = new RedisSentinel ( sentinelHosts , TestConfig . MasterName ) {
106+ HostFilter = host => "{0}?db=1" . Fmt ( host )
111107 } ;
112108
113109 using ( var clientsManager = sentinel . Setup ( ) )
You can’t perform that action at this time.
0 commit comments