0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/pubsub/redis-streams
History 2026-11-12 21:12:29 +00:00
..
src fix(core): send only the response messages that changed on agent stream events (#29971) 2026-11-10 23:13:38 -03:00
test-fixtures fix: index observe chunks for resume (COR-1506) (#29520) 2026-11-06 11:40:46 -08:00
.gitignore feat(core,server,cli,redis-streams): standalone workers + push-capable PubSub + Redis Streams broker (#16309) 2026-05-08 14:01:20 +03:00
CHANGELOG.md chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
docker-compose.yaml chore(deps): update docker images (#28011) 2026-10-29 15:53:50 +00:00
lint-staged.config.js refactor(lint): replace ESLint with type-aware oxlint (#27476) 2026-10-18 10:38:35 -07:00
package.json chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
README.md fix(redis-streams,valkey-streams): expire idle streams by default and clear them on thread delete (#28968) 2026-10-30 11:51:23 +01:00
tsconfig.build.json feat(core,server,cli,redis-streams): standalone workers + push-capable PubSub + Redis Streams broker (#16309) 2026-05-08 14:01:20 +03:00
tsconfig.json test(redis-streams): run durable worker-takeover suite against real Redis and Postgres (#28952) 2026-11-03 11:41:25 -08:00
tsconfig.test.json test(redis-streams): run durable worker-takeover suite against real Redis and Postgres (#28952) 2026-11-03 11:41:25 -08:00
tsdown.config.ts chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
vitest.config.ts feat(core,server,cli,redis-streams): standalone workers + push-capable PubSub + Redis Streams broker (#16309) 2026-05-08 14:01:20 +03:00

@mastra/redis-streams

RedisStreamsPubSub implements Mastra's PubSub and lease-provider contracts with Redis Streams. Use it for durable event delivery, consumer-group coordination, and workflow leases across multiple processes or hosts.

Installation

npm install @mastra/redis-streams

Usage

Requires Redis 7.0 or later.

import { Mastra } from '@mastra/core/mastra';
import { RedisStreamsPubSub } from '@mastra/redis-streams';

export const mastra = new Mastra({
  pubsub: new RedisStreamsPubSub({
    url: process.env.REDIS_URL!,
    keyPrefix: 'mastra:my-app',
  }),
});

Every stream gets a sliding idle TTL, controlled by streamIdleTtlMs (default: 7 days). Every write refreshes it, so actively written topics never expire, while abandoned ones (a crashed run, or open-ended topics that never reach a clearTopic call) are reclaimed by Redis once they go idle. Reads do not refresh the TTL, so keep it above the longest expected gap between writes on a live topic, including the time a grouped consumer may need to replay a backlog. Setting streamIdleTtlMs: 0 disables expiry; those streams then stay in Redis forever and its memory grows without bound.

Redis Cluster

Pass cluster (forwarded to createCluster() from redis) instead of url/redisOptions:

import { RedisStreamsPubSub } from '@mastra/redis-streams';

const pubsub = new RedisStreamsPubSub({
  cluster: { rootNodes: [{ url: 'redis://node-1:6379' }, { url: 'redis://node-2:6379' }] },
});

To build the client yourself (TLS, credential providers), pass an unconnected client instead; readers are created from it with client.duplicate() and the pubsub owns its lifecycle.

Documentation

Changelog

See the package changelog for version history and release notes.

Support

We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.