Class RedisSaver

A Redis implementation of the BaseCheckpointSaver for LangGraph.

This saver stores checkpoint data in Redis, providing durable persistence across application restarts. It supports both the node-redis and ioredis clients.

Example

import { RedisSaver } from "langgraph-db/providers/redis";

// Create a Redis-backed checkpoint saver
const saver = new RedisSaver({
url: "redis://localhost:6379",
ttl: 3600 // 1 hour TTL (optional)
});

// Use with a LangGraph
const graph = new StateGraph({
channels: { input: { value: "" } },
nodes: {}, // define your nodes here
checkpointer: saver
});

Example

// Using with IORedis
import { RedisSaver } from "langgraph-db/providers/redis";
import IORedis from "ioredis";

// Create an IORedis client
const ioredisClient = new IORedis("redis://localhost:6379");

// Create a Redis-backed checkpoint saver with IORedis
const saver = new RedisSaver({
client: ioredisClient,
ttl: 3600 // 1 hour TTL (optional)
});

Example

// Retrieving checkpoints
import { RedisSaver } from "langgraph-db/providers/redis";

const saver = new RedisSaver();
await saver.connect();

// Get a specific checkpoint by ID
const checkpoint = await saver.getTuple({
configurable: {
thread_id: "user_123",
checkpoint_id: "abc123",
checkpoint_ns: "conversation"
}
});

// Or get the most recent checkpoint for a thread
const latestCheckpoint = await saver.getTuple({
configurable: {
thread_id: "user_123",
checkpoint_ns: "conversation"
}
});

Example

// Listing checkpoints with filtering
import { RedisSaver } from "langgraph-db/providers/redis";

const saver = new RedisSaver();

// List all checkpoints for a thread with filtering
const checkpoints = [];
for await (const checkpoint of saver.list({
configurable: { thread_id: "user_123" }
}, {
filter: { status: "completed" }, // Filter by metadata
limit: 10 // Limit to 10 results
})) {
checkpoints.push(checkpoint);
}

Example

// Manual cleanup when done
import { RedisSaver } from "langgraph-db/providers/redis";

const saver = new RedisSaver();

try {
// Use the saver...
} finally {
// Properly disconnect when done
await saver.disconnect();
}

Hierarchy

  • BaseCheckpointSaver
    • RedisSaver

Constructors

Properties

client: RedisAdapter
clientOwned: boolean = false
connectionPromise: null | Promise<void> = null
isConnecting: boolean = false
serde: SerializerProtocol
storage: Record<string, Record<string, Record<string, [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, undefined | string]>>> = {}
ttl?: number
writes: Record<string, Record<string, [string, string, Uint8Array<ArrayBufferLike>]>> = {}

Methods

  • Gets pending sends from the parent checkpoint.

    Parameters

    • threadId: string
    • checkpointNs: string
    • Optional parentCheckpointId: string

    Returns Promise<SendProtocol[]>

  • Sets a value in Redis with optional TTL.

    Parameters

    • key: string

      The Redis key

    • value: string | Buffer<ArrayBufferLike>

      The value to store

    Returns Promise<void>

  • Parameters

    • config: RunnableConfig<Record<string, any>>

    Returns Promise<undefined | Checkpoint<string, string>>

  • Generate the next version ID for a channel.

    Default is to use integer versions, incrementing by 1. If you override, you can use str/int/float versions, as long as they are monotonically increasing.

    Parameters

    • current: undefined | number
    • _channel: ChannelProtocol<unknown, unknown, unknown>

    Returns number

  • Retrieves a checkpoint tuple by config.

    Parameters

    • config: RunnableConfig<Record<string, any>>

      The runnable config

    Returns Promise<undefined | CheckpointTuple>

    The checkpoint tuple or undefined if not found

  • Lists checkpoints matching the given config and options.

    Parameters

    • config: RunnableConfig<Record<string, any>>

      The runnable config

    • Optional options: CheckpointListOptions

      Listing options

    Returns AsyncGenerator<CheckpointTuple, any, any>

    An async generator of checkpoint tuples

  • Stores a checkpoint with its configuration and metadata.

    Parameters

    • config: RunnableConfig<Record<string, any>>

      The runnable config

    • checkpoint: Checkpoint<string, string>

      The checkpoint data

    • metadata: CheckpointMetadata

      The checkpoint metadata

    Returns Promise<RunnableConfig<Record<string, any>>>

    Updated runnable config

  • Stores intermediate writes linked to a checkpoint.

    Parameters

    • config: RunnableConfig<Record<string, any>>

      The runnable config

    • writes: PendingWrite[]

      The pending writes

    • taskId: string

      The task ID

    Returns Promise<void>