Redis Storage
High-performance storage adapter for high-throughput workflows
Redis Storage
The @stepflowjs/storage-redis adapter provides a high-performance storage backend using Redis. It is ideal for high-throughput scenarios and uses Lua scripts for atomic operations and the Redlock pattern for distributed locking.
Installation
pnpm add @stepflowjs/storage-redisUsage
import { Stepflow } from "@stepflowjs/core";
import { RedisStorageAdapter } from "@stepflowjs/storage-redis";
const stepflow = new Stepflow({
storage: new RedisStorageAdapter({
url: process.env.REDIS_URL,
// Optional: key prefix (defaults to "stepflow:")
keyPrefix: "myapp:workflows:",
}),
});Configuration Options
| Option | Type | Description |
|---|---|---|
url | string | Redis connection URL |
host | string | Redis host (default: localhost) |
port | number | Redis port (default: 6379) |
password | string | Redis password |
db | number | Redis database index (default: 0) |
keyPrefix | string | Prefix for all keys stored in Redis (default: stepflow:) |
Features
- High Throughput: Optimized for low-latency state transitions.
- Atomic Operations: Uses Lua scripts to ensure atomicity for complex operations like job popping.
- Distributed Locking: Implements the Redlock pattern for reliable leader election.
- Pub/Sub: Uses Redis Pub/Sub for real-time execution updates.
Environment Variables
REDIS_URL=redis://:password@localhost:6379/0