This commit is contained in:
nvms 2025-04-18 17:52:25 -04:00
parent 36eed400b8
commit 0579c0d150

View File

@ -158,11 +158,11 @@ sequenceDiagram
end
```
### Redis channel subscriptions
## Redis channel subscriptions
Mesh lets clients subscribe to Redis pub/sub channels and receive messages directly over their WebSocket connection. When subscribing, clients can optionally request recent message history.
#### Server configuration
### Server configuration
Expose the channels you want to allow subscriptions to:
@ -178,7 +178,7 @@ server.exposeChannel(/^private:chat:.+$/, async (conn, channel) => {
});
```
#### Server publishing
### Server publishing
To publish messages to a channel (which subscribed clients will receive), use the `publishToChannel` method. You can optionally store a history of recent messages in Redis.
@ -199,7 +199,7 @@ await server.publishToChannel(
The `history` parameter tells Mesh to store the message in a Redis list (`history:<channel>`) and trim the list to the specified size, ensuring only the most recent messages are kept. Clients subscribing with the `historyLimit` option will receive these historical messages upon connection.
#### Client usage
### Client usage
```ts
const { success, history } = await client.subscribe(