@mastra/redis 1.0.1 → 1.0.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @mastra/redis
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed Redis package releases to include built files. ([#15763](https://github.com/mastra-ai/mastra/pull/15763))
8
+
9
+ - Updated dependencies [[`28caa5b`](https://github.com/mastra-ai/mastra/commit/28caa5b032358545af2589ed90636eccb4dd9d2f), [`c1ae974`](https://github.com/mastra-ai/mastra/commit/c1ae97491f6e57378ce880c3a397778c42adcdf1), [`b510d36`](https://github.com/mastra-ai/mastra/commit/b510d368f73dab6be2e2c2bc99035aaef1fb7d7a), [`13b4d7c`](https://github.com/mastra-ai/mastra/commit/13b4d7c16de34dff9095d1cd80f22f544b6cfe75), [`7a7b313`](https://github.com/mastra-ai/mastra/commit/7a7b3138fb3bcf0b0c740eaea07971e43d330ef3), [`c04417b`](https://github.com/mastra-ai/mastra/commit/c04417ba0a2e4ded66da4352331ef29cd4bd1d79), [`cf25a03`](https://github.com/mastra-ai/mastra/commit/cf25a03132164b9dc1e5dccf7394824e33007c51), [`8a71261`](https://github.com/mastra-ai/mastra/commit/8a71261e3954ae617c6f8e25767b951f99438ab2), [`9e973b0`](https://github.com/mastra-ai/mastra/commit/9e973b010dacfa15ac82b0072897319f5234b90a), [`dd934a0`](https://github.com/mastra-ai/mastra/commit/dd934a0982ce0f78712fbd559e4f2410bf594b39), [`ba6b0c5`](https://github.com/mastra-ai/mastra/commit/ba6b0c51bfce358554fd33c7f2bcd5593633f2ff), [`a6dac0a`](https://github.com/mastra-ai/mastra/commit/a6dac0a40c7181161b1add4e8534f962bcbc9aa7), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`6c8c6c7`](https://github.com/mastra-ai/mastra/commit/6c8c6c71518394321a4692614aa4b11f3bb0a343), [`5a4b1ee`](https://github.com/mastra-ai/mastra/commit/5a4b1ee80212969621228104995589c0fa59e575), [`7d056b6`](https://github.com/mastra-ai/mastra/commit/7d056b6ecf603cacaa0f663ff1df025ed885b6c1), [`9cef83b`](https://github.com/mastra-ai/mastra/commit/9cef83b8a642b8098747772921e3523b492bafbc), [`d30e215`](https://github.com/mastra-ai/mastra/commit/d30e2156c746bc9fd791745cec1cc24377b66789), [`021a60f`](https://github.com/mastra-ai/mastra/commit/021a60f1f3e0135a70ef23c58be7a9b3aaffe6b4), [`73f2809`](https://github.com/mastra-ai/mastra/commit/73f2809721db24e98cdf122539652a455211b450), [`aedeea4`](https://github.com/mastra-ai/mastra/commit/aedeea48a94f728323f040478775076b9574be50), [`26f1f94`](https://github.com/mastra-ai/mastra/commit/26f1f9490574b864ba1ecedf2c9632e0767a23bd), [`8126d86`](https://github.com/mastra-ai/mastra/commit/8126d8638411eacfafdc29036ac998e8757ea66f), [`73b45fa`](https://github.com/mastra-ai/mastra/commit/73b45facdef4fbcb8af710c50f0646f18619dbaa), [`ae97520`](https://github.com/mastra-ai/mastra/commit/ae975206fdb0f6ef03c4d5bf94f7dc7c3f706c02), [`7a7b313`](https://github.com/mastra-ai/mastra/commit/7a7b3138fb3bcf0b0c740eaea07971e43d330ef3), [`441670a`](https://github.com/mastra-ai/mastra/commit/441670a02c9dc7731c52674f55481e7848a84523)]:
10
+ - @mastra/core@1.29.0
11
+
12
+ ## 1.0.2-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Fixed Redis package releases to include built files. ([#15763](https://github.com/mastra-ai/mastra/pull/15763))
17
+
3
18
  ## 1.0.1
4
19
 
5
20
  ### Patch Changes
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: mastra-redis
3
+ description: Documentation for @mastra/redis. Use when working with @mastra/redis APIs, configuration, or implementation.
4
+ metadata:
5
+ package: "@mastra/redis"
6
+ version: "1.0.2"
7
+ ---
8
+
9
+ ## When to use
10
+
11
+ Use this skill whenever you are working with @mastra/redis to obtain the domain-specific knowledge.
12
+
13
+ ## How to use
14
+
15
+ Read the individual reference documents for detailed explanations and code examples.
16
+
17
+ ### Reference
18
+
19
+ - [Reference: Redis Storage](references/reference-storage-redis.md) - Documentation for the Redis storage implementation in Mastra.
20
+
21
+
22
+ Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": "1.0.2",
3
+ "package": "@mastra/redis",
4
+ "exports": {},
5
+ "modules": {}
6
+ }
@@ -0,0 +1,266 @@
1
+ # Redis Storage
2
+
3
+ The Redis storage implementation provides a high-performance storage solution using direct Redis connections via [node-redis](https://github.com/redis/node-redis) (the official Redis client for Node.js). It supports standalone Redis, and through custom client configuration, Redis Sentinel and Cluster deployments.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/redis
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Using Connection String
14
+
15
+ ```typescript
16
+ import { RedisStore } from '@mastra/redis'
17
+
18
+ const storage = new RedisStore({
19
+ id: 'redis-storage',
20
+ connectionString: 'redis://localhost:6379',
21
+ })
22
+
23
+ await storage.init()
24
+ ```
25
+
26
+ ### Using Host/Port Configuration
27
+
28
+ ```typescript
29
+ import { RedisStore } from '@mastra/redis'
30
+
31
+ const storage = new RedisStore({
32
+ id: 'redis-storage',
33
+ host: 'localhost',
34
+ port: 6379,
35
+ password: 'your-password',
36
+ db: 0,
37
+ })
38
+
39
+ await storage.init()
40
+ ```
41
+
42
+ ### Using Pre-configured Client
43
+
44
+ For advanced configurations like Sentinel or Cluster, you can pass a pre-configured redis client:
45
+
46
+ ```typescript
47
+ import { RedisStore } from '@mastra/redis'
48
+ import { createClient } from 'redis'
49
+
50
+ const client = createClient({
51
+ url: 'redis://localhost:6379',
52
+ socket: {
53
+ reconnectStrategy: retries => Math.min(retries * 50, 2000),
54
+ },
55
+ })
56
+
57
+ // Connect the client before passing to RedisStore
58
+ await client.connect()
59
+
60
+ const storage = new RedisStore({
61
+ id: 'redis-storage',
62
+ client,
63
+ })
64
+ ```
65
+
66
+ ## Parameters
67
+
68
+ **id** (`string`): Unique identifier for the storage instance
69
+
70
+ **connectionString** (`string`): Redis connection URL (e.g., \`redis\://localhost:6379\` or \`redis\://:password\@localhost:6379\`)
71
+
72
+ **host** (`string`): Redis host address
73
+
74
+ **port** (`number`): Redis port number (Default: `6379`)
75
+
76
+ **password** (`string`): Redis password for authentication
77
+
78
+ **db** (`number`): Redis database number (Default: `0`)
79
+
80
+ **client** (`RedisClient`): Pre-configured redis client (from the \`redis\` package) for advanced setups
81
+
82
+ > **Note:** You must provide either `connectionString`, `host`, or `client`. These options are mutually exclusive.
83
+
84
+ ## Additional Notes
85
+
86
+ ### Key Structure
87
+
88
+ The Redis storage implementation uses the following key patterns:
89
+
90
+ - Threads: `mastra_threads:id:{threadId}`
91
+ - Messages: `mastra_messages:threadId:{threadId}:id:{messageId}`
92
+ - Message index: `msg-idx:{messageId}` (for fast lookups)
93
+ - Thread messages sorted set: `thread:{threadId}:messages`
94
+ - Workflow snapshots: `mastra_workflow_snapshot:namespace:{ns}:workflow_name:{name}:run_id:{id}`
95
+ - Scores: `mastra_scorers:id:{scoreId}`
96
+ - Resources: `mastra_resources:{resourceId}`
97
+
98
+ ### Redis Sentinel
99
+
100
+ For high-availability deployments using Redis Sentinel, create a custom client:
101
+
102
+ ```typescript
103
+ import { RedisStore } from '@mastra/redis'
104
+ import { createClient } from 'redis'
105
+
106
+ const client = createClient({
107
+ url: 'redis://sentinel-host:26379',
108
+ // Configure sentinel options as needed for your setup
109
+ })
110
+
111
+ await client.connect()
112
+
113
+ const storage = new RedisStore({
114
+ id: 'redis-sentinel-storage',
115
+ client,
116
+ })
117
+ ```
118
+
119
+ ### Redis Cluster
120
+
121
+ For Redis Cluster deployments, use the cluster client:
122
+
123
+ ```typescript
124
+ import { RedisStore } from '@mastra/redis'
125
+ import { createCluster } from 'redis'
126
+
127
+ const cluster = createCluster({
128
+ rootNodes: [
129
+ { url: 'redis://node-1:6379' },
130
+ { url: 'redis://node-2:6379' },
131
+ { url: 'redis://node-3:6379' },
132
+ ],
133
+ })
134
+
135
+ await cluster.connect()
136
+
137
+ const storage = new RedisStore({
138
+ id: 'redis-cluster-storage',
139
+ client: cluster,
140
+ })
141
+ ```
142
+
143
+ ### Accessing the Underlying Client
144
+
145
+ You can access the underlying redis client for custom operations:
146
+
147
+ ```typescript
148
+ const storage = new RedisStore({
149
+ id: 'redis-storage',
150
+ connectionString: 'redis://localhost:6379',
151
+ })
152
+
153
+ await storage.init()
154
+
155
+ const client = storage.getClient()
156
+
157
+ // Custom Redis operations
158
+ await client.set('custom-key', 'value')
159
+ const value = await client.get('custom-key')
160
+ ```
161
+
162
+ ### Closing Connections
163
+
164
+ When shutting down your application, close the Redis connection:
165
+
166
+ ```typescript
167
+ await storage.close()
168
+ ```
169
+
170
+ ## Usage Example
171
+
172
+ ### Adding memory to an agent
173
+
174
+ ```typescript
175
+ import { Memory } from '@mastra/memory'
176
+ import { Agent } from '@mastra/core/agent'
177
+ import { RedisStore } from '@mastra/redis'
178
+
179
+ export const redisAgent = new Agent({
180
+ id: 'redis-agent',
181
+ name: 'Redis Agent',
182
+ instructions:
183
+ 'You are an AI agent with the ability to automatically recall memories from previous interactions.',
184
+ model: 'openai/gpt-4o',
185
+ memory: new Memory({
186
+ storage: new RedisStore({
187
+ id: 'redis-agent-storage',
188
+ connectionString: process.env.REDIS_URL!,
189
+ }),
190
+ options: {
191
+ lastMessages: 10,
192
+ },
193
+ }),
194
+ })
195
+ ```
196
+
197
+ ### Using the agent
198
+
199
+ ```typescript
200
+ import 'dotenv/config'
201
+
202
+ import { mastra } from './mastra'
203
+
204
+ const threadId = '123'
205
+ const resourceId = 'user-456'
206
+
207
+ const agent = mastra.getAgent('redisAgent')
208
+
209
+ const message = await agent.stream('My name is Mastra', {
210
+ memory: {
211
+ thread: threadId,
212
+ resource: resourceId,
213
+ },
214
+ })
215
+
216
+ await message.textStream.pipeTo(new WritableStream())
217
+
218
+ const stream = await agent.stream("What's my name?", {
219
+ memory: {
220
+ thread: threadId,
221
+ resource: resourceId,
222
+ },
223
+ memoryOptions: {
224
+ lastMessages: 5,
225
+ },
226
+ })
227
+
228
+ for await (const chunk of stream.textStream) {
229
+ process.stdout.write(chunk)
230
+ }
231
+ ```
232
+
233
+ ### Using with Mastra instance
234
+
235
+ ```typescript
236
+ import { Mastra } from '@mastra/core'
237
+ import { RedisStore } from '@mastra/redis'
238
+
239
+ const storage = new RedisStore({
240
+ id: 'mastra-storage',
241
+ host: 'localhost',
242
+ port: 6379,
243
+ })
244
+
245
+ const mastra = new Mastra({
246
+ storage, // init() called automatically
247
+ })
248
+ ```
249
+
250
+ If using storage directly without Mastra, call `init()` explicitly:
251
+
252
+ ```typescript
253
+ import { RedisStore } from '@mastra/redis'
254
+
255
+ const storage = new RedisStore({
256
+ id: 'redis-storage',
257
+ host: 'localhost',
258
+ port: 6379,
259
+ })
260
+
261
+ await storage.init()
262
+
263
+ // Access domain-specific stores via getStore()
264
+ const memoryStore = await storage.getStore('memory')
265
+ const thread = await memoryStore?.getThreadById({ threadId: '...' })
266
+ ```