Skip to main content
Redis stores agent state in memory for sub-millisecond access — pair it with a SQL backend for conversation history.
from praisonaiagents import Agent, db

agent = Agent(
    name="FastBot",
    instructions="You are a helpful assistant.",
    db=db(state_url="redis://localhost:6379"),
    session_id="redis-session",
)
agent.start("Store my preferences in Redis")
The user updates session state; Redis serves fast reads while SQL can hold conversation history.

Quick Start

1

Simple Usage

pip install redis praisonai
from praisonaiagents import Agent, db

agent = Agent(
    name="FastBot",
    db=db(state_url="redis://localhost:6379"),
    session_id="session-1",
)
agent.start("Hello!")
2

With Configuration

Hybrid setup — SQL for conversations, Redis for state:
from praisonaiagents import Agent, db

agent = Agent(
    name="HybridBot",
    db=db(
        database_url="postgresql://user:pass@localhost/conversations",
        state_url="redis://localhost:6379",
    ),
    session_id="hybrid-session",
)
agent.start("Conversations in Postgres, state in Redis")

How It Works

Redis is a state store — fast key-value access for agent preferences and runtime data. Conversation history uses database_url separately.
FeatureDescription
In-memory speedSub-millisecond reads and writes
TTL supportExpire keys automatically with ttl
Key prefixNamespace keys with prefix (default praison:)

Configuration Options

OptionTypeDefaultDescription
urlstrNoneFull Redis URL (overrides host/port/db/password)
hoststr"localhost"Redis host when url is not set
portint6379Redis port
dbint0Redis database number
passwordstrNoneRedis password
prefixstr"praison:"Key prefix for namespacing
decode_responsesboolTrueCompatibility flag (not used internally)
socket_timeoutint5Socket timeout in seconds
max_connectionsint10Compatibility flag for pool size

URL formats

db(state_url="redis://localhost:6379")
db(state_url="redis://:password@host:6379/0")

Best Practices

Use database_url for chat history and state_url for fast ephemeral state.
Pass ttl when storing session-scoped data that should expire automatically.
Set prefix="prod:" vs prefix="staging:" to isolate keys on a shared Redis instance.
Configure Redis AOF or RDB snapshots if state must survive Redis restarts.

MongoDB State Store

Document-based state with flexible schemas

Database Persistence

Overview of conversation and state backends