Skip to content

Commit 40d1eb2

Browse files
Merge pull request #1491 from redis/DOC-5192-csharp-prod-usage
DOC-5192 added C# production usage page
2 parents c93b216 + e450d78 commit 40d1eb2

File tree

6 files changed

+117
-5
lines changed

6 files changed

+117
-5
lines changed

content/develop/clients/dotnet/condexec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ categories:
1212
description: Understand how `NRedisStack` uses conditional execution
1313
linkTitle: Conditional execution
1414
title: Conditional execution
15-
weight: 6
15+
weight: 60
1616
---
1717

1818
Most Redis client libraries use transactions with the

content/develop/clients/dotnet/connect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ categories:
1212
description: Connect your .NET application to a Redis database
1313
linkTitle: Connect
1414
title: Connect to the server
15-
weight: 2
15+
weight: 20
1616
---
1717

1818
## Basic connection
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
categories:
3+
- docs
4+
- develop
5+
- stack
6+
- oss
7+
- rs
8+
- rc
9+
- oss
10+
- kubernetes
11+
- clients
12+
description: Get your NRedisStack app ready for production
13+
linkTitle: Production usage
14+
title: Production usage
15+
weight: 70
16+
---
17+
18+
This guide offers recommendations to get the best reliability and
19+
performance in your production environment.
20+
21+
## Checklist
22+
23+
Each item in the checklist below links to the section
24+
for a recommendation. Use the checklist icons to record your
25+
progress in implementing the recommendations.
26+
27+
{{< checklist "dotnetprodlist" >}}
28+
{{< checklist-item "#event-handling" >}}Event handling{{< /checklist-item >}}
29+
{{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}}
30+
{{< checklist-item "#exception-handling" >}}Exception handling{{< /checklist-item >}}
31+
{{< /checklist >}}
32+
33+
## Recommendations
34+
35+
The sections below offer recommendations for your production environment. Some
36+
of them may not apply to your particular use case.
37+
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
51+
52+
Some servers (such as Azure Cache for Redis) send notification events shortly
53+
before scheduled maintenance is due to happen. You can use code like the
54+
following to respond to these events (see the
55+
[StackExchange.Redis](https://stackexchange.github.io/StackExchange.Redis/ServerMaintenanceEvent)
56+
docs for the full list of supported events). For example, you could
57+
inform users who try to connect that service is temporarily unavailable
58+
rather than letting them run into errors.
59+
60+
```cs
61+
using NRedisStack;
62+
using StackExchange.Redis;
63+
64+
ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect("localhost:6379");
65+
66+
muxer.ServerMaintenanceEvent += (object sender, ServerMaintenanceEvent e) => {
67+
// Identify the event and respond to it here.
68+
Console.WriteLine($"Maintenance event: {e.RawMessage}");
69+
};
70+
```
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+
99+
### Exception handling
100+
101+
Redis handles many errors using return values from commands, but there
102+
are also situations where exceptions can be thrown. In production code,
103+
you should handle exceptions as they occur. The list below describes some
104+
the most common Redis exceptions:
105+
106+
- `RedisConnectionException`: Thrown when a connection attempt fails.
107+
- `RedisTimeoutException`: Thrown when a command times out.
108+
- `RedisCommandException`: Thrown when you issue an invalid command.
109+
- `RedisServerException`: Thrown when you attempt an invalid operation
110+
(for example, trying to access a
111+
[stream entry]({{< relref "/develop/data-types/streams#entry-ids" >}})
112+
using an invalid ID).

content/develop/clients/dotnet/queryjson.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ categories:
1212
description: Learn how to use the Redis query engine with JSON and hash documents.
1313
linkTitle: Index and query documents
1414
title: Index and query documents
15-
weight: 2
15+
weight: 30
1616
---
1717

1818
This example shows how to create a

content/develop/clients/dotnet/transpipe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ categories:
1212
description: Learn how to use Redis pipelines and transactions
1313
linkTitle: Pipelines/transactions
1414
title: Pipelines and transactions
15-
weight: 5
15+
weight: 50
1616
---
1717

1818
Redis lets you send a sequence of commands to the server together in a batch.

content/develop/clients/dotnet/vecsearch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ categories:
1212
description: Learn how to index and query vector embeddings with Redis
1313
linkTitle: Index and query vectors
1414
title: Index and query vectors
15-
weight: 3
15+
weight: 40
1616
---
1717

1818
[Redis Query Engine]({{< relref "/develop/interact/search-and-query" >}})

0 commit comments

Comments
 (0)