Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 771870d

Browse files
committed
Add SentinelHostFilter for customizing Sentinel Host configuration strings
1 parent ae0a470 commit 771870d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/ServiceStack.Redis/RedisSentinel.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ public class RedisSentinel : IRedisSentinel
4242
public Func<string[], string[], IRedisClientsManager> RedisManagerFactory { get; set; }
4343

4444
/// <summary>
45-
/// Configure the Redis Connection String to use for a Redis Client Host
45+
/// Configure the Redis Connection String to use for a Redis Instance Host
4646
/// </summary>
4747
public Func<string, string> HostFilter { get; set; }
4848

49+
/// <summary>
50+
/// Configure the Redis Connection String to use for a Redis Sentinel Host
51+
/// </summary>
52+
public Func<string, string> SentinelHostFilter { get; set; }
53+
4954
/// <summary>
5055
/// The configured Redis Client Manager this Sentinel managers
5156
/// </summary>
@@ -185,15 +190,18 @@ public List<string> GetActiveSentinelHosts(IEnumerable<string> sentinelHosts)
185190
var endpoint = sentinelHost.ToRedisEndpoint(defaultPort: RedisConfig.DefaultPortSentinel);
186191
using (var sentinelWorker = new RedisSentinelWorker(this, endpoint))
187192
{
188-
var activeHosts = sentinelWorker.GetSentinelHosts(MasterName);
189-
190193
if (!activeSentinelHosts.Contains(sentinelHost))
191194
activeSentinelHosts.Add(sentinelHost);
192195

196+
var activeHosts = sentinelWorker.GetSentinelHosts(MasterName);
193197
foreach (var activeHost in activeHosts)
194198
{
195199
if (!activeSentinelHosts.Contains(activeHost))
196-
activeSentinelHosts.Add(activeHost);
200+
{
201+
activeSentinelHosts.Add(SentinelHostFilter != null
202+
? SentinelHostFilter(activeHost)
203+
: activeHost);
204+
}
197205
}
198206
}
199207

0 commit comments

Comments
 (0)