Commit e1976ed
committed
Add Redis connection factory and manager
`IRedisConnectionManager` is a singleton service responsible for
initialising the connection to the Redis cluster and recreating it in
the rare cases [1] where it fails to reconnect after a transient
connection failure.
It is based heavily on the `RedisConnection` class in the Azure Cache
for Redis sample for ASP.NET Core [2] with a few notable differences:
- `IRedisConnectionManager` is not responsible for providing any retry
logic. Instead, consumers are expected to call
`IRedisConnectionManager.CheckException` when an exception occurs
making a call to Redis. This return value indicates whether the
exception could have been caused by a transient connection error,
which the caller can use to decide whether to perform a retry.
- I've added separate configuration options
(`DroppedConnectionGracePeriod` and `DroppedConnectionEpisodeTimeout`)
for the two conditions checked against `RedisErrorThreshold` in the
Azure Cache for Redis sample
- `RedisConnectionManager` implements `IAsyncDisposable` instead of
`IDisposable`
I've abstracted the creation of Redis connections into a separate
`IRedisConnectionFactory` service purely to facilitate unit testing of
`RedisConnectionManager`. This interface is not intended to be consumed
directly and is therefore internal to the assembly.
[1] StackExchange/StackExchange.Redis#559
[2] https://github.com/Azure-Samples/azure-cache-redis-samples/blob/main/quickstart/aspnet-core/ContosoTeamStats/RedisConnection.cs1 parent bf2b9dd commit e1976ed
File tree
13 files changed
+826
-0
lines changed- src
- Buttercup.Redis.Tests
- Buttercup.Redis
13 files changed
+826
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
215 | 219 | | |
216 | 220 | | |
217 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
218 | 246 | | |
219 | 247 | | |
220 | 248 | | |
| |||
231 | 259 | | |
232 | 260 | | |
233 | 261 | | |
| 262 | + | |
| 263 | + | |
234 | 264 | | |
235 | 265 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments