Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion src/content/docs/how-to/monitoring/monitor-command.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
:::
Comment on lines +117 to +120

Copy link
Copy Markdown
Collaborator

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.


```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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix the C# examples validation.

</TabItem>
</Tabs>

### Queue mode
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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:
Expand All @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This C#-only block should not be necessary.

2 changes: 1 addition & 1 deletion src/data/available-commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
{ "command": "MODULE LOAD", "valkey-io": "/commands/module-load", "python": "not_available", "node": "not_available", "java": "not_available", "go": "not_available", "csharp": "not_available", "php": "not_available", "python-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "node-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "java-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "go-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "csharp-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "php-href": "https://github.com/valkey-io/valkey-glide/issues/6292" },
{ "command": "MODULE LOADEX", "valkey-io": "/commands/module-loadex", "python": "not_available", "node": "not_available", "java": "not_available", "go": "not_available", "php": "not_available", "csharp": "not_available", "python-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "node-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "java-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "go-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "csharp-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "php-href": "https://github.com/valkey-io/valkey-glide/issues/6292" },
{ "command": "MODULE UNLOAD", "valkey-io": "/commands/module-unload", "python": "not_available", "node": "not_available", "java": "not_available", "go": "not_available", "csharp": "not_available", "php": "not_available", "python-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "node-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "java-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "go-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "csharp-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "php-href": "https://github.com/valkey-io/valkey-glide/issues/6292" },
{ "command": "MONITOR", "valkey-io": "/commands/monitor", "python": "available", "node": "available", "java": "available", "go": "available", "csharp": "not_available", "php": "not_available", "python-href": "/how-to/monitoring/monitor-command", "node-href": "/how-to/monitoring/monitor-command", "java-href": "/how-to/monitoring/monitor-command", "go-href": "/how-to/monitoring/monitor-command", "csharp-href": "https://github.com/valkey-io/valkey-glide/issues/5978", "php-href": "https://github.com/valkey-io/valkey-glide/issues/5978" },
{ "command": "MONITOR", "valkey-io": "/commands/monitor", "python": "available", "node": "available", "java": "available", "go": "available", "csharp": "available", "php": "not_available", "python-href": "/how-to/monitoring/monitor-command", "node-href": "/how-to/monitoring/monitor-command", "java-href": "/how-to/monitoring/monitor-command", "go-href": "/how-to/monitoring/monitor-command", "csharp-href": "/how-to/monitoring/monitor-command", "php-href": "https://github.com/valkey-io/valkey-glide/issues/5978" },
{ "command": "PSYNC", "valkey-io": "/commands/psync", "python": "not_available", "node": "not_available", "java": "not_available", "go": "not_available", "csharp": "not_available", "php": "not_available", "href": "#incompatible-commands" },
{ "command": "REPLCONF", "valkey-io": "/commands/replconf", "python": "not_available", "node": "not_available", "java": "not_available", "go": "not_available", "csharp": "not_available", "php": "not_available", "python-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "node-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "java-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "go-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "csharp-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "php-href": "https://github.com/valkey-io/valkey-glide/issues/6292" },
{ "command": "REPLICAOF", "valkey-io": "/commands/replicaof", "python": "available", "node": "available", "java": "available", "go": "available", "csharp": "not_available", "php": "not_available", "python-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "node-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "go-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "csharp-href": "https://github.com/valkey-io/valkey-glide/issues/6292", "php-href": "https://github.com/valkey-io/valkey-glide/issues/6292" },
Expand Down
Loading