Advertisement
Guest User

RedisConnector

a guest
Jul 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. public class RedisConnector
  2.     {
  3.         private static Lazy<ConfigurationOptions> configOptions = new Lazy<ConfigurationOptions>(
  4.             () => {
  5.                 var configOptions = new ConfigurationOptions();
  6.                 configOptions.EndPoints.Add("172.17.0.1:6379");
  7.                 configOptions.ClientName = "RedisConnection";
  8.                 configOptions.ConnectTimeout = 10000;
  9.                 configOptions.SyncTimeout = 3000;
  10.                 configOptions.AbortOnConnectFail = false;
  11.                 configOptions.DefaultDatabase = _environment.IsProduction() ? 0 : 1;
  12.                 return configOptions;
  13.             });
  14.  
  15.         private static Lazy<ConnectionMultiplexer> _connection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(configOptions.Value));
  16.         private static IHostingEnvironment _environment;
  17.  
  18.         protected ConnectionMultiplexer RedisConnection
  19.         {
  20.             get {
  21.                 return _connection.Value;
  22.             }
  23.         }
  24.  
  25.         protected IDatabase RedisDB
  26.         {
  27.             get { return RedisConnection.GetDatabase(); }
  28.         }
  29.  
  30.         public RedisConnector(IConfiguration configuration, IHostingEnvironment environemnt)
  31.         {
  32.             _environment = environemnt;
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement