This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new overridable RedisManagerFactory to RedisSentinel with configu…
…rable OnInit filter
- Loading branch information
Showing
6 changed files
with
112 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace ServiceStack.Redis | ||
{ | ||
public class RedisManagerFactory | ||
{ | ||
public Action<IRedisClientsManager> OnInit { get; set; } | ||
|
||
public Func<IEnumerable<string>, IEnumerable<string>, IRedisClientsManager> FactoryFn { get; set; } | ||
|
||
public RedisManagerFactory() | ||
{ | ||
FactoryFn = CreatePooledRedisClientManager; | ||
} | ||
|
||
public static IRedisClientsManager CreatePooledRedisClientManager( | ||
IEnumerable<string> readWriteHosts, | ||
IEnumerable<string> readOnlyHosts) | ||
{ | ||
return readOnlyHosts.Any() | ||
? new PooledRedisClientManager(readWriteHosts, readOnlyHosts) | ||
: new PooledRedisClientManager(readWriteHosts.ToArray()); | ||
} | ||
|
||
public static IRedisClientsManager CreateBasicRedisClientManager( | ||
IEnumerable<string> readWriteHosts, | ||
IEnumerable<string> readOnlyHosts) | ||
{ | ||
return readOnlyHosts.Any() | ||
? new BasicRedisClientManager(readWriteHosts, readOnlyHosts) | ||
: new BasicRedisClientManager(readWriteHosts.ToArray()); | ||
} | ||
|
||
public static IRedisClientsManager CreateRedisManager( | ||
IEnumerable<string> readWriteHosts, | ||
IEnumerable<string> readOnlyHosts) | ||
{ | ||
return new RedisManagerPool(readWriteHosts); | ||
} | ||
|
||
public IRedisClientsManager Create(IEnumerable<string> readWriteHosts, IEnumerable<string> readOnlyHosts) | ||
{ | ||
var redisManager = FactoryFn(readWriteHosts, readOnlyHosts); | ||
if (OnInit != null) | ||
OnInit(redisManager); | ||
|
||
return redisManager; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters