@@ -25,7 +25,8 @@ for a recommendation. Use the checklist icons to record your
25
25
progress in implementing the recommendations.
26
26
27
27
{{< checklist "dotnetprodlist" >}}
28
- {{< checklist-item "#server-maintenance-event-handling" >}}Server maintenance event handling{{< /checklist-item >}}
28
+ {{< checklist-item "#event-handling" >}}Event handling{{< /checklist-item >}}
29
+ {{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}}
29
30
{{< checklist-item "#exception-handling" >}}Exception handling{{< /checklist-item >}}
30
31
{{< /checklist >}}
31
32
@@ -34,7 +35,19 @@ progress in implementing the recommendations.
34
35
The sections below offer recommendations for your production environment. Some
35
36
of them may not apply to your particular use case.
36
37
37
- ### Server maintenance event handling
38
+ ### Event handling
39
+
40
+ The ` ConnectionMultiplexer ` class publishes several different types of
41
+ [ events] ( https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/ )
42
+ for situations such as configuration changes and connection failures.
43
+ Use these events to record server activity in a log, which you can then use
44
+ to monitor performance and diagnose problems when they occur.
45
+ See
46
+ the StackExchange.Redis
47
+ [ Events] ( https://stackexchange.github.io/StackExchange.Redis/Events )
48
+ page for the full list of events.
49
+
50
+ #### Server notification events
38
51
39
52
Some servers (such as Azure Cache for Redis) send notification events shortly
40
53
before scheduled maintenance is due to happen. You can use code like the
@@ -56,6 +69,33 @@ muxer.ServerMaintenanceEvent += (object sender, ServerMaintenanceEvent e) => {
56
69
};
57
70
```
58
71
72
+ ### Timeouts
73
+
74
+ If a network or server error occurs while your code is opening a
75
+ connection or issuing a command, it can end up hanging indefinitely.
76
+ To prevent this, ` NRedisStack ` sets timeouts for socket
77
+ reads and writes and for opening connections.
78
+
79
+ By default, the timeout is five seconds for all operations, but
80
+ you can set the time (in milliseconds) separately for connections
81
+ and commands using the ` ConnectTimeout ` , ` SyncTimeout ` , and
82
+ ` AsyncTimeout ` configuration options:
83
+
84
+ ``` cs
85
+ var muxer = ConnectionMultiplexer .Connect (new ConfigurationOptions {
86
+ ConnectTimeout = 1000 , // 1 second timeout for connections.
87
+ SyncTimeout = 2000 , // 2 seconds for synchronous commands.
88
+ AsyncTimeout = 3000 // 3 seconds for asynchronous commands.
89
+ .
90
+ .
91
+ });
92
+
93
+ var db = muxer .GetDatabase ();
94
+ ```
95
+
96
+ The default timeouts are a good starting point, but you may be able
97
+ to improve performance by adjusting the values to suit your use case.
98
+
59
99
### Exception handling
60
100
61
101
Redis handles many errors using return values from commands, but there
0 commit comments