@@ -7,9 +7,9 @@ namespace Learning.EventStore.Common.Redis
7
7
{
8
8
public class RedisClient : IRedisClient , IDisposable
9
9
{
10
- private readonly Lazy < IConnectionMultiplexer > _redis ;
10
+ private readonly IConnectionMultiplexer _redisConnection ;
11
11
12
- public IDatabase Database => _redis . Value . GetDatabase ( ) ;
12
+ public IDatabase Database => _redisConnection . GetDatabase ( ) ;
13
13
14
14
private readonly int _retryCount ;
15
15
@@ -29,14 +29,33 @@ public class RedisClient : IRedisClient, IDisposable
29
29
retryAttempt => TimeSpan . FromSeconds ( Math . Pow ( 2 , retryAttempt ) ) // exponential backoff
30
30
) ;
31
31
32
- public RedisClient ( Lazy < IConnectionMultiplexer > redis )
33
- : this ( redis , 3 )
32
+ /// <summary>
33
+ /// DEPRECATED: Use the constructor that takes a non-lazy loaded IConnectionMultiplexer
34
+ /// </summary>
35
+ /// <param name="redisConnection"></param>
36
+ public RedisClient ( Lazy < IConnectionMultiplexer > redisConnection )
37
+ : this ( redisConnection , 3 )
34
38
{
35
39
}
36
40
37
- public RedisClient ( Lazy < IConnectionMultiplexer > redis , int retryCount )
41
+ /// <summary>
42
+ /// DEPRECATED: Use the constructor that takes a non-lazy loaded IConnectionMultiplexer
43
+ /// </summary>
44
+ /// <param name="redisConnection"></param>
45
+ /// <param name="retryCount"></param>
46
+ public RedisClient ( Lazy < IConnectionMultiplexer > redisConnection , int retryCount )
47
+ : this ( redisConnection . Value , retryCount )
38
48
{
39
- _redis = redis ;
49
+ }
50
+
51
+ public RedisClient ( IConnectionMultiplexer redisConnectionConnection )
52
+ : this ( redisConnectionConnection , 3 )
53
+ {
54
+ }
55
+
56
+ public RedisClient ( IConnectionMultiplexer redisConnectionConnection , int retryCount )
57
+ {
58
+ _redisConnection = redisConnectionConnection ;
40
59
_retryCount = retryCount ;
41
60
}
42
61
@@ -108,12 +127,12 @@ public long ListRemove(RedisKey key, RedisValue value)
108
127
109
128
public async Task PublishAsync ( RedisChannel channel , RedisValue value )
110
129
{
111
- await RetryPolicyAsync . ExecuteAsync ( ( ) => _redis . Value . GetSubscriber ( ) . PublishAsync ( channel , value ) ) . ConfigureAwait ( false ) ;
130
+ await RetryPolicyAsync . ExecuteAsync ( ( ) => _redisConnection . GetSubscriber ( ) . PublishAsync ( channel , value ) ) . ConfigureAwait ( false ) ;
112
131
}
113
132
114
133
public async Task SubscribeAsync ( RedisChannel channel , Action < RedisChannel , RedisValue > handler )
115
134
{
116
- await RetryPolicyAsync . ExecuteAsync ( ( ) => _redis . Value . GetSubscriber ( ) . SubscribeAsync ( channel , handler ) ) . ConfigureAwait ( false ) ;
135
+ await RetryPolicyAsync . ExecuteAsync ( ( ) => _redisConnection . GetSubscriber ( ) . SubscribeAsync ( channel , handler ) ) . ConfigureAwait ( false ) ;
117
136
}
118
137
119
138
public async Task < string > StringGetAsync ( string key )
@@ -218,7 +237,7 @@ public async Task<bool> ExecuteTransactionAsync(ITransaction trans)
218
237
219
238
public void Dispose ( )
220
239
{
221
- _redis . Value . Dispose ( ) ;
240
+ _redisConnection . Dispose ( ) ;
222
241
}
223
242
}
224
243
}
0 commit comments