-
Notifications
You must be signed in to change notification settings - Fork 16
docs: add C# MONITOR command support #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { Tabs, TabItem } from '@astrojs/starlight/components'; | |
|
|
||
| The MONITOR command streams every command processed by the Valkey server back to the client in real time. It is intended for debugging and development only. | ||
|
|
||
| MONITOR is supported in Python, Node.js, Java, and Go clients. C# and PHP support is not yet available. | ||
| MONITOR is supported in Python, Node.js, Java, Go, and C# clients. PHP support is not yet available. | ||
|
|
||
| ## How It Works | ||
|
|
||
|
|
@@ -113,6 +113,29 @@ There are two modes for consuming monitor messages: | |
| } | ||
| ``` | ||
| </TabItem> | ||
|
|
||
| <TabItem label="C#"> | ||
| :::note | ||
| The C# client uses `IAsyncEnumerable<MonitorMessage>` instead of callbacks. Messages are consumed via `await foreach` with native cancellation support. | ||
| ::: | ||
|
|
||
| ```csharp | ||
| using Valkey.Glide; | ||
|
|
||
| // Create a MonitorConfig (implements IDisposable for secure credential handling) | ||
| using var config = new MonitorConfig("localhost", 6379); | ||
|
|
||
| // Create the monitor client | ||
| await using var monitor = await MonitorClient.CreateClient(config); | ||
|
|
||
| // Consume messages as an async stream with cancellation support | ||
| using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); | ||
| await foreach (MonitorMessage msg in monitor.GetMessagesAsync(cts.Token)) | ||
| { | ||
| Console.WriteLine($"{msg.Timestamp:O} [{msg.Database}] {msg.ClientAddress} {msg.Command} {string.Join(" ", msg.Args)}"); | ||
| } | ||
| ``` | ||
|
Comment on lines
+122
to
+137
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to fix the C# examples validation. |
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ### Queue mode | ||
|
|
@@ -196,8 +219,45 @@ There are two modes for consuming monitor messages: | |
| } | ||
| ``` | ||
| </TabItem> | ||
|
|
||
| <TabItem label="C#"> | ||
| :::note | ||
| The C# client does not have a separate queue mode. `GetMessagesAsync()` returns an `IAsyncEnumerable` that can be consumed one message at a time or as a continuous stream. | ||
| ::: | ||
|
|
||
| ```csharp | ||
| using Valkey.Glide; | ||
|
|
||
| // Create a MonitorConfig (implements IDisposable for secure credential handling) | ||
| using var config = new MonitorConfig("localhost", 6379); | ||
|
|
||
| // Create the monitor client | ||
| await using var monitor = await MonitorClient.CreateClient(config); | ||
|
|
||
| // Consume messages as an async stream with cancellation support | ||
| using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); | ||
| await foreach (MonitorMessage msg in monitor.GetMessagesAsync(cts.Token)) | ||
| { | ||
| Console.WriteLine($"{msg.Timestamp:O} [{msg.Database}] {msg.ClientAddress} {msg.Command} {string.Join(" ", msg.Args)}"); | ||
| } | ||
| ``` | ||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## C# Configuration | ||
|
|
||
| The C# client uses the `MonitorConfig` fluent API for connection configuration: | ||
|
|
||
| ```csharp | ||
| using var config = new MonitorConfig("localhost", 6379) | ||
| .WithTls() // Enable TLS | ||
| .WithAuth("password") // Password-only auth | ||
| .WithAuth("user", "password") // Username + password auth | ||
| .WithDatabase(2); // Select database | ||
| ``` | ||
|
|
||
| Note: `MonitorConfig` implements `IDisposable` — it clears the password array on dispose for secure credential handling. | ||
|
Comment on lines
+247
to
+259
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C#-only section does not seem necessary. |
||
|
|
||
| ## Monitor Message Fields | ||
|
|
||
| Each monitor message contains the following fields: | ||
|
|
@@ -209,3 +269,15 @@ Each monitor message contains the following fields: | |
| | `clientAddr` | string | Address of the client that issued the command | | ||
| | `command` | string | Command name | | ||
| | `args` | list/array | Command arguments | | ||
|
Comment on lines
261
to
271
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be generalized to apply to all clients. |
||
|
|
||
| ## C# Type Mapping | ||
|
|
||
| In the C# client, `MonitorMessage` is a strongly-typed class: | ||
|
|
||
| | Property | Type | | ||
| | --- | --- | | ||
| | `Timestamp` | `DateTimeOffset` | | ||
| | `Database` | `ushort` | | ||
| | `ClientAddress` | `string` | | ||
| | `Command` | `string` | | ||
| | `Args` | `IReadOnlyList<string>` | | ||
|
Comment on lines
+273
to
+283
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This C#-only block should not be necessary. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we update the comments above, I don't think this comment will be necessary.