chat 4.18.0 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,100 +0,0 @@
1
- ---
2
- title: Redis
3
- description: Production state adapter using the official redis package.
4
- type: reference
5
- prerequisites:
6
- - /docs/getting-started
7
- ---
8
-
9
- The recommended state adapter for production. Uses the official [redis](https://www.npmjs.com/package/redis) package.
10
-
11
- ## Installation
12
-
13
- ```sh title="Terminal"
14
- pnpm add @chat-adapter/state-redis
15
- ```
16
-
17
- ## Usage
18
-
19
- `createRedisState()` auto-detects the `REDIS_URL` environment variable, so you can call it with no arguments:
20
-
21
- ```typescript title="lib/bot.ts" lineNumbers
22
- import { Chat } from "chat";
23
- import { createRedisState } from "@chat-adapter/state-redis";
24
-
25
- const bot = new Chat({
26
- userName: "mybot",
27
- adapters: { /* ... */ },
28
- state: createRedisState(),
29
- });
30
- ```
31
-
32
- To provide a URL explicitly:
33
-
34
- ```typescript title="lib/bot.ts"
35
- const state = createRedisState({ url: "redis://localhost:6379" });
36
- ```
37
-
38
- ### Using an existing client
39
-
40
- If you already have a connected Redis client, pass it directly:
41
-
42
- ```typescript title="lib/bot.ts" lineNumbers
43
- import { createClient } from "redis";
44
-
45
- const client = createClient({ url: "redis://localhost:6379" });
46
- await client.connect();
47
-
48
- const state = createRedisState({ client });
49
- ```
50
-
51
- ### Key prefix
52
-
53
- All keys are namespaced under a configurable prefix (default: `"chat-sdk"`):
54
-
55
- ```typescript title="lib/bot.ts" lineNumbers
56
- const state = createRedisState({
57
- url: process.env.REDIS_URL!,
58
- keyPrefix: "my-bot",
59
- });
60
- ```
61
-
62
- ## Configuration
63
-
64
- | Option | Required | Description |
65
- |--------|----------|-------------|
66
- | `url` | No* | Redis connection URL (auto-detected from `REDIS_URL`) |
67
- | `client` | No | Existing `redis` client instance |
68
- | `keyPrefix` | No | Prefix for all keys (default: `"chat-sdk"`) |
69
- | `logger` | No | Logger instance (defaults to `ConsoleLogger("info")`) |
70
-
71
- *Either `url`, `REDIS_URL` env var, or `client` is required.
72
-
73
- ## Environment variables
74
-
75
- ```bash title=".env.local"
76
- REDIS_URL=redis://localhost:6379
77
- ```
78
-
79
- For serverless deployments (Vercel, AWS Lambda), use a serverless-compatible Redis provider like [Upstash](https://upstash.com).
80
-
81
- ## Key structure
82
-
83
- ```
84
- {keyPrefix}:subscriptions - SET of subscribed thread IDs
85
- {keyPrefix}:lock:{threadId} - Lock key with TTL
86
- ```
87
-
88
- ## Production recommendations
89
-
90
- - Use Redis 6.0+ for best performance
91
- - Enable Redis persistence (RDB or AOF)
92
- - Use Redis Cluster for high availability
93
- - Set appropriate memory limits
94
-
95
- ## Features
96
-
97
- - Persistent subscriptions across restarts
98
- - Distributed locking across multiple instances
99
- - Automatic reconnection
100
- - Key prefix namespacing