diff --git a/content/develop/clients/dotnet/condexec.md b/content/develop/clients/dotnet/condexec.md index dc89e40c5..f08d602bf 100644 --- a/content/develop/clients/dotnet/condexec.md +++ b/content/develop/clients/dotnet/condexec.md @@ -12,7 +12,7 @@ categories: description: Understand how `NRedisStack` uses conditional execution linkTitle: Conditional execution title: Conditional execution -weight: 6 +weight: 60 --- Most Redis client libraries use transactions with the diff --git a/content/develop/clients/dotnet/connect.md b/content/develop/clients/dotnet/connect.md index b9ad53006..152b351a9 100644 --- a/content/develop/clients/dotnet/connect.md +++ b/content/develop/clients/dotnet/connect.md @@ -12,7 +12,7 @@ categories: description: Connect your .NET application to a Redis database linkTitle: Connect title: Connect to the server -weight: 2 +weight: 20 --- ## Basic connection diff --git a/content/develop/clients/dotnet/produsage.md b/content/develop/clients/dotnet/produsage.md new file mode 100644 index 000000000..9d3bf7be2 --- /dev/null +++ b/content/develop/clients/dotnet/produsage.md @@ -0,0 +1,112 @@ +--- +categories: +- docs +- develop +- stack +- oss +- rs +- rc +- oss +- kubernetes +- clients +description: Get your NRedisStack app ready for production +linkTitle: Production usage +title: Production usage +weight: 70 +--- + +This guide offers recommendations to get the best reliability and +performance in your production environment. + +## Checklist + +Each item in the checklist below links to the section +for a recommendation. Use the checklist icons to record your +progress in implementing the recommendations. + +{{< checklist "dotnetprodlist" >}} + {{< checklist-item "#event-handling" >}}Event handling{{< /checklist-item >}} + {{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}} + {{< checklist-item "#exception-handling" >}}Exception handling{{< /checklist-item >}} +{{< /checklist >}} + +## Recommendations + +The sections below offer recommendations for your production environment. Some +of them may not apply to your particular use case. + +### Event handling + +The `ConnectionMultiplexer` class publishes several different types of +[events](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/) +for situations such as configuration changes and connection failures. +Use these events to record server activity in a log, which you can then use +to monitor performance and diagnose problems when they occur. +See +the StackExchange.Redis +[Events](https://stackexchange.github.io/StackExchange.Redis/Events) +page for the full list of events. + +#### Server notification events + +Some servers (such as Azure Cache for Redis) send notification events shortly +before scheduled maintenance is due to happen. You can use code like the +following to respond to these events (see the +[StackExchange.Redis](https://stackexchange.github.io/StackExchange.Redis/ServerMaintenanceEvent) +docs for the full list of supported events). For example, you could +inform users who try to connect that service is temporarily unavailable +rather than letting them run into errors. + +```cs +using NRedisStack; +using StackExchange.Redis; + +ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect("localhost:6379"); + +muxer.ServerMaintenanceEvent += (object sender, ServerMaintenanceEvent e) => { + // Identify the event and respond to it here. + Console.WriteLine($"Maintenance event: {e.RawMessage}"); +}; +``` + +### Timeouts + +If a network or server error occurs while your code is opening a +connection or issuing a command, it can end up hanging indefinitely. +To prevent this, `NRedisStack` sets timeouts for socket +reads and writes and for opening connections. + +By default, the timeout is five seconds for all operations, but +you can set the time (in milliseconds) separately for connections +and commands using the `ConnectTimeout`, `SyncTimeout`, and +`AsyncTimeout` configuration options: + +```cs +var muxer = ConnectionMultiplexer.Connect(new ConfigurationOptions { + ConnectTimeout = 1000, // 1 second timeout for connections. + SyncTimeout = 2000, // 2 seconds for synchronous commands. + AsyncTimeout = 3000 // 3 seconds for asynchronous commands. + . + . +}); + +var db = muxer.GetDatabase(); +``` + +The default timeouts are a good starting point, but you may be able +to improve performance by adjusting the values to suit your use case. + +### Exception handling + +Redis handles many errors using return values from commands, but there +are also situations where exceptions can be thrown. In production code, +you should handle exceptions as they occur. The list below describes some +the most common Redis exceptions: + +- `RedisConnectionException`: Thrown when a connection attempt fails. +- `RedisTimeoutException`: Thrown when a command times out. +- `RedisCommandException`: Thrown when you issue an invalid command. +- `RedisServerException`: Thrown when you attempt an invalid operation + (for example, trying to access a + [stream entry]({{< relref "/develop/data-types/streams#entry-ids" >}}) + using an invalid ID). diff --git a/content/develop/clients/dotnet/queryjson.md b/content/develop/clients/dotnet/queryjson.md index a6ee76ebe..e643e3ed1 100644 --- a/content/develop/clients/dotnet/queryjson.md +++ b/content/develop/clients/dotnet/queryjson.md @@ -12,7 +12,7 @@ categories: description: Learn how to use the Redis query engine with JSON and hash documents. linkTitle: Index and query documents title: Index and query documents -weight: 2 +weight: 30 --- This example shows how to create a diff --git a/content/develop/clients/dotnet/transpipe.md b/content/develop/clients/dotnet/transpipe.md index b3e74198c..4fe82af54 100644 --- a/content/develop/clients/dotnet/transpipe.md +++ b/content/develop/clients/dotnet/transpipe.md @@ -12,7 +12,7 @@ categories: description: Learn how to use Redis pipelines and transactions linkTitle: Pipelines/transactions title: Pipelines and transactions -weight: 5 +weight: 50 --- Redis lets you send a sequence of commands to the server together in a batch. diff --git a/content/develop/clients/dotnet/vecsearch.md b/content/develop/clients/dotnet/vecsearch.md index 018cdab2e..31ffcbf3a 100644 --- a/content/develop/clients/dotnet/vecsearch.md +++ b/content/develop/clients/dotnet/vecsearch.md @@ -12,7 +12,7 @@ categories: description: Learn how to index and query vector embeddings with Redis linkTitle: Index and query vectors title: Index and query vectors -weight: 3 +weight: 40 --- [Redis Query Engine]({{< relref "/develop/interact/search-and-query" >}})