@@ -13,12 +13,11 @@ Configure adapters in `motia.config.ts`. If you don't specify any, Motia uses de
1313import { config } from ' @motiadev/core'
1414import { RedisStateAdapter } from ' @motiadev/adapter-redis-state'
1515
16+ const redisUrl = ` redis://${process .env .REDIS_HOST || ' localhost' }:6379 `
17+
1618export default config ({
1719 adapters: {
18- state: new RedisStateAdapter ({
19- host: process .env .REDIS_HOST ,
20- port: 6379
21- })
20+ state: new RedisStateAdapter ({ url: redisUrl })
2221 }
2322})
2423```
@@ -79,12 +78,14 @@ For multi-instance deployments. Shares state and events across instances.
7978import { config } from ' @motiadev/core'
8079import { RedisStateAdapter } from ' @motiadev/adapter-redis-state'
8180
81+ const redisUrl = ` redis://${process .env .REDIS_HOST || ' localhost' }:${process .env .REDIS_PORT || ' 6379' } `
82+
8283export default config ({
8384 adapters: {
84- state: new RedisStateAdapter ({
85- host: process . env . REDIS_HOST || ' localhost ' ,
86- port: parseInt ( process . env . REDIS_PORT || ' 6379 ' )
87- } )
85+ state: new RedisStateAdapter (
86+ { url: redisUrl } ,
87+ { keyPrefix: ' myapp: ' , ttl: 3600 }
88+ )
8889 }
8990})
9091```
@@ -96,12 +97,14 @@ export default config({
9697const { config } = require (' @motiadev/core' )
9798const { RedisStateAdapter } = require (' @motiadev/adapter-redis-state' )
9899
100+ const redisUrl = ` redis://${ process .env .REDIS_HOST || ' localhost' } :${ process .env .REDIS_PORT || ' 6379' } `
101+
99102module .exports = config ({
100103 adapters: {
101- state: new RedisStateAdapter ({
102- host : process . env . REDIS_HOST || ' localhost ' ,
103- port : parseInt ( process . env . REDIS_PORT || ' 6379 ' )
104- } )
104+ state: new RedisStateAdapter (
105+ { url : redisUrl } ,
106+ { keyPrefix : ' myapp: ' , ttl : 3600 }
107+ )
105108 }
106109})
107110```
@@ -124,12 +127,11 @@ npm install @motiadev/adapter-redis-state
124127import { config } from ' @motiadev/core'
125128import { RedisStreamAdapterManager } from ' @motiadev/adapter-redis-streams'
126129
130+ const redisUrl = ` redis://${process .env .REDIS_HOST || ' localhost' }:${process .env .REDIS_PORT || ' 6379' } `
131+
127132export default config ({
128133 adapters: {
129- streams: new RedisStreamAdapterManager ({
130- host: process .env .REDIS_HOST || ' localhost' ,
131- port: parseInt (process .env .REDIS_PORT || ' 6379' )
132- })
134+ streams: new RedisStreamAdapterManager ({ url: redisUrl })
133135 }
134136})
135137```
@@ -141,12 +143,11 @@ export default config({
141143const { config } = require (' @motiadev/core' )
142144const { RedisStreamAdapterManager } = require (' @motiadev/adapter-redis-streams' )
143145
146+ const redisUrl = ` redis://${ process .env .REDIS_HOST || ' localhost' } :${ process .env .REDIS_PORT || ' 6379' } `
147+
144148module .exports = config ({
145149 adapters: {
146- streams: new RedisStreamAdapterManager ({
147- host: process .env .REDIS_HOST || ' localhost' ,
148- port: parseInt (process .env .REDIS_PORT || ' 6379' )
149- })
150+ streams: new RedisStreamAdapterManager ({ url: redisUrl })
150151 }
151152})
152153```
@@ -216,12 +217,11 @@ npm install @motiadev/adapter-rabbitmq-events
216217import { config } from ' @motiadev/core'
217218import { RedisCronAdapter } from ' @motiadev/adapter-redis-cron'
218219
220+ const redisUrl = ` redis://${process .env .REDIS_HOST || ' localhost' }:${process .env .REDIS_PORT || ' 6379' } `
221+
219222export default config ({
220223 adapters: {
221- cron: new RedisCronAdapter ({
222- host: process .env .REDIS_HOST || ' localhost' ,
223- port: parseInt (process .env .REDIS_PORT || ' 6379' )
224- })
224+ cron: new RedisCronAdapter ({ url: redisUrl })
225225 }
226226})
227227```
@@ -233,12 +233,11 @@ export default config({
233233const { config } = require (' @motiadev/core' )
234234const { RedisCronAdapter } = require (' @motiadev/adapter-redis-cron' )
235235
236+ const redisUrl = ` redis://${ process .env .REDIS_HOST || ' localhost' } :${ process .env .REDIS_PORT || ' 6379' } `
237+
236238module .exports = config ({
237239 adapters: {
238- cron: new RedisCronAdapter ({
239- host: process .env .REDIS_HOST || ' localhost' ,
240- port: parseInt (process .env .REDIS_PORT || ' 6379' )
241- })
240+ cron: new RedisCronAdapter ({ url: redisUrl })
242241 }
243242})
244243```
@@ -265,25 +264,24 @@ import { RedisStreamAdapterManager } from '@motiadev/adapter-redis-streams'
265264import { RabbitMQEventAdapter } from ' @motiadev/adapter-rabbitmq-events'
266265import { RedisCronAdapter } from ' @motiadev/adapter-redis-cron'
267266
267+ const redisUrl = ` redis://${process .env .REDIS_HOST || ' localhost' }:6379 `
268+
268269export default config ({
269270 adapters: {
270- state: new RedisStateAdapter ({
271- host: process .env .REDIS_HOST || ' localhost' ,
272- port: 6379
273- }),
274- streams: new RedisStreamAdapterManager ({
275- host: process .env .REDIS_HOST || ' localhost' ,
276- port: 6379
277- }),
271+ state: new RedisStateAdapter (
272+ { url: redisUrl },
273+ { keyPrefix: ' myapp:state:' }
274+ ),
275+ streams: new RedisStreamAdapterManager ({ url: redisUrl }),
278276 events: new RabbitMQEventAdapter ({
279277 url: process .env .RABBITMQ_URL || ' amqp://localhost' ,
280278 exchangeName: ' motia.events' ,
281279 exchangeType: ' topic'
282280 }),
283- cron: new RedisCronAdapter ({
284- host: process . env . REDIS_HOST || ' localhost ' ,
285- port: 6379
286- } )
281+ cron: new RedisCronAdapter (
282+ { url: redisUrl } ,
283+ { keyPrefix: ' myapp:cron: ' }
284+ )
287285 }
288286})
289287```
@@ -306,3 +304,41 @@ export default config({
306304
307305---
308306
307+ ## Configuration Tips
308+
309+ ### Redis URL Format
310+
311+ Build Redis URLs from environment variables:
312+
313+ ``` typescript
314+ // Basic connection
315+ const redisUrl = ` redis://localhost:6379 `
316+
317+ // With password
318+ const redisUrl = ` redis://:password@localhost:6379 `
319+
320+ // With username and password
321+ const redisUrl = ` redis://user:password@localhost:6379 `
322+
323+ // From environment variables
324+ const redisUrl = ` redis://${process .env .REDIS_HOST }:${process .env .REDIS_PORT } `
325+ ```
326+
327+ ### Adapter Options
328+
329+ Redis adapters accept two parameters:
330+
331+ ``` typescript
332+ new RedisStateAdapter (
333+ { url: redisUrl }, // Connection config
334+ { keyPrefix: ' app:' , ttl: 3600 } // Adapter options
335+ )
336+ ```
337+
338+ ** Common options:**
339+ - ` keyPrefix ` - Prefix for all keys (helps organize data)
340+ - ` ttl ` - Time-to-live in seconds (auto-expire old data)
341+ - ` lockTTL ` - Lock timeout for cron jobs
342+
343+ ---
344+
0 commit comments