@@ -15,36 +15,35 @@ public class Broker
1515 public string SecondaryWaitingQueueName { get { return QueueBaseName + ":SecondaryWaiting" ; } }
1616 public string SecondaryProcessingQueueName { get { return QueueBaseName + ":SecondaryProcessing" ; } }
1717
18+ private static Lazy < ConnectionMultiplexer > lazyConnection = new Lazy < ConnectionMultiplexer > ( ( ) => {
19+ var queueSettings = InEngineSettings . Make ( ) . Queue ;
20+ var redisConfig = ConfigurationOptions . Parse ( $ "{ queueSettings . RedisHost } :{ queueSettings . RedisPort } ") ;
21+ redisConfig . Password = string . IsNullOrWhiteSpace ( queueSettings . RedisPassword ) ?
22+ null :
23+ queueSettings . RedisPassword ;
24+ redisConfig . AbortOnConnectFail = false ;
25+ return ConnectionMultiplexer . Connect ( redisConfig ) ;
26+ } ) ;
27+
28+ public static ConnectionMultiplexer Connection { get { return lazyConnection . Value ; } }
29+
1830 public ConnectionMultiplexer _connectionMultiplexer ;
1931 public IDatabase Redis
2032 {
2133 get
2234 {
23- if ( _connectionMultiplexer == null || ! _connectionMultiplexer . IsConnected )
24- {
25- var redisConfig = ConfigurationOptions . Parse ( $ "{ RedisHost } :{ RedisPort } ") ;
26- redisConfig . Password = string . IsNullOrWhiteSpace ( RedisPassword ) ? null : RedisPassword ;
27- redisConfig . AbortOnConnectFail = false ;
28- _connectionMultiplexer = ConnectionMultiplexer . Connect ( redisConfig ) ;
29- }
30- return _connectionMultiplexer . GetDatabase ( RedisDb ) ;
35+ return Connection . GetDatabase ( RedisDb ) ;
3136 }
3237 }
33- public string RedisHost { get ; set ; }
34- public int RedisDb { get ; set ; }
35- public int RedisPort { get ; set ; }
36- public string RedisPassword { get ; set ; }
38+ public static string RedisHost { get ; set ; }
39+ public static int RedisDb { get ; set ; }
40+ public static int RedisPort { get ; set ; }
41+ public static string RedisPassword { get ; set ; }
3742
3843 public static Broker Make ( )
3944 {
40- var queueSettings = InEngineSettings . Make ( ) . Queue ;
41- return new Broker ( )
42- {
43- QueueBaseName = queueSettings . QueueName ,
44- RedisHost = queueSettings . RedisHost ,
45- RedisPort = queueSettings . RedisPort ,
46- RedisDb = queueSettings . RedisDb ,
47- RedisPassword = queueSettings . RedisPassword ,
45+ return new Broker ( ) {
46+ QueueBaseName = InEngineSettings . Make ( ) . Queue . QueueName
4847 } ;
4948 }
5049
0 commit comments