Jido.Storage.Redis
(Jido v2.2.0)
View Source
Redis-based storage adapter for agent checkpoints and thread journals.
Durable storage suitable when you already operate Redis and want an
optional external backing store for Jido. The adapter does not depend
on a Redis client; callers provide a 1-arity :command_fn.
Usage
defmodule MyApp.RedisStorage do
def command(cmd), do: Redix.command(:my_redis, cmd)
end
defmodule MyApp.Jido do
use Jido,
otp_app: :my_app,
storage: {Jido.Storage.Redis, [
command_fn: &MyApp.RedisStorage.command/1,
prefix: "jido"
]}
endOptions
:command_fn(required) — A function that executes Redis commands. Signature:fn [binary()] -> {:ok, term()} | {:error, term()}This keeps Redis client choice in the caller.:prefix(optional, default"jido") — Key prefix for namespacing.:ttl(optional) — TTL in milliseconds for all keys. When set, keys expire automatically.
Key Layout
{prefix}:cp:{hex_hash} → Serialized checkpoint
{prefix}:th:{thread_id} → Serialized thread stateThread journals are stored as a single serialized value containing revision, timestamps, metadata, and entries. Using one key avoids partial writes between thread entries and metadata.
Concurrency
Thread operations use :global.trans/3 for distributed locking, matching
the pattern used by Jido.Storage.ETS and Jido.Storage.File.
Summary
Types
@type opts() :: keyword()
@type stored_thread() :: %{ rev: non_neg_integer(), created_at: integer(), updated_at: integer(), metadata: map(), entries: [Jido.Thread.Entry.t()] }