StepflowStepflow

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-redis

Usage

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

OptionTypeDescription
urlstringRedis connection URL
hoststringRedis host (default: localhost)
portnumberRedis port (default: 6379)
passwordstringRedis password
dbnumberRedis database index (default: 0)
keyPrefixstringPrefix 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

On this page