ValkeyStreamsPubSub
ValkeyStreamsPubSub is a PubSub and LeaseProvider implementation backed by Valkey Streams through Valkey GLIDE. It provides persistent cross-process delivery, consumer groups, redelivery, topic cleanup, and distributed leasing.
Use it for Valkey deployments. Use RedisStreamsPubSub for Redis deployments that use the official redis client. Both integrations implement the same Mastra behavior, with independent tests running against Valkey and Redis.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/valkey-streams
pnpm add @mastra/valkey-streams
yarn add @mastra/valkey-streams
bun add @mastra/valkey-streams
Usage exampleDirect link to Usage example
import { Mastra } from '@mastra/core'
import { ValkeyStreamsPubSub } from '@mastra/valkey-streams'
export const mastra = new Mastra({
pubsub: new ValkeyStreamsPubSub({
url: 'valkey://localhost:6379',
}),
})
Constructor parametersDirect link to Constructor parameters
url?:
valkeyOptions.url.valkeyOptions?:
keyPrefix?:
blockMs?:
maxStreamLength?:
streamIdleTtlMs?:
reclaimIntervalMs?:
reclaimIdleMs?:
maxDeliveryAttempts?:
Infinity to disable the cap.logger?:
Delivery behaviorDirect link to Delivery behavior
ValkeyStreamsPubSub supports pull delivery and doesn't support numeric replay offsets. Grouped subscribers compete for events through a shared consumer group. Subscribers without a group receive fan-out delivery through private consumer groups.
Use startFrom: "latest" to skip retained entries when a group is first created. The default, "earliest", reads retained entries first.
Cleanup and shutdownDirect link to Cleanup and shutdown
clearTopic(topic) deletes a topic stream and its consumer groups. flush() waits for in-flight publishes, and close() stops subscriptions and closes GLIDE connections.
await pubsub.clearTopic('workflow.events.run-123')
await pubsub.flush()
await pubsub.close()