Skip to content

Redis backend

The default Store is in-memory: fast, but its state is gone when the process exits and can't be shared with other processes. When you need state to survive restarts or be shared across workers/services, use RedisStore - it has the exact same interface as Store, so it drops in anywhere a store is expected (including the LangGraph checkpointer) with no other code changes.

Values are serialized with msgpack - the same wire format as the Rust core - so anything written here is readable by any msgpack consumer, in any language.

pip install "swarmstate[redis]"
# or: uv add "swarmstate[redis]"

Use it like a Store

from swarmstate.backends.redis import RedisStore

store = RedisStore("redis://localhost:6379/0")
store.set("workflow", "onboarding", {"step": 3})
store.get("workflow", "onboarding")     # -> {"step": 3}
store.keys("workflow")                  # -> ["onboarding"]
store.namespaces()                      # -> ["workflow"]

It implements the full interface: set, get, contains, delete, keys, namespaces, clear, len(store), plus snapshot() / restore() (copy-based, O(n) - Redis persists rather than offering the Rust store's O(1) structural-sharing snapshots).

Persistent LangGraph checkpoints

Because RedisStore shares the store interface, it drops straight into SwarmStateSaver - giving you persistent checkpoints that survive process restarts and are shared across workers:

from swarmstate.backends.redis import RedisStore
from swarmstate.integrations.langgraph import SwarmStateSaver

saver = SwarmStateSaver(RedisStore("redis://localhost:6379/0"))
graph = builder.compile(checkpointer=saver)
# a fresh process pointed at the same Redis resumes every thread

Layout & format

  • Each namespace is a Redis hash at {prefix}:{namespace} (default prefix swarmstate); fields are keys, values are msgpack bytes.
  • The msgpack encoding is standard, so a value written here decodes with any msgpack library - the foundation of cross-framework state portability.

Parameters

Parameter Default Description
url redis://localhost:6379/0 Redis connection URL
client None pass an existing redis.Redis client instead of a URL
prefix "swarmstate" key prefix namespacing this store
codec "msgpack" value serialization (stable, cross-language)