Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RedisConnector
- {
- private static Lazy<ConfigurationOptions> configOptions = new Lazy<ConfigurationOptions>(
- () => {
- var configOptions = new ConfigurationOptions();
- configOptions.EndPoints.Add("172.17.0.1:6379");
- configOptions.ClientName = "RedisConnection";
- configOptions.ConnectTimeout = 10000;
- configOptions.SyncTimeout = 3000;
- configOptions.AbortOnConnectFail = false;
- configOptions.DefaultDatabase = _environment.IsProduction() ? 0 : 1;
- return configOptions;
- });
- private static Lazy<ConnectionMultiplexer> _connection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(configOptions.Value));
- private static IHostingEnvironment _environment;
- protected ConnectionMultiplexer RedisConnection
- {
- get {
- return _connection.Value;
- }
- }
- protected IDatabase RedisDB
- {
- get { return RedisConnection.GetDatabase(); }
- }
- public RedisConnector(IConfiguration configuration, IHostingEnvironment environemnt)
- {
- _environment = environemnt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement