RedisDb class.
Usage
Run Redis
Install docker desktop and run Redis on port 6379 using:docker run -d \
--name my-redis \
-p 6379:6379 \
redis
redis_for_agent.py
from agno.agent import Agent
from agno.db.base import SessionType
from agno.db.redis import RedisDb
from agno.tools.hackernews import HackerNewsTools
# Initialize Redis db (use the right db_url for your setup)
db = RedisDb(db_url="redis://localhost:6379")
# Create agent with Redis db
agent = Agent(
db=db,
tools=[HackerNewsTools()],
add_history_to_context=True,
)
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
# Verify db contents
print("\nVerifying db contents...")
all_sessions = db.get_sessions(session_type=SessionType.AGENT)
print(f"Total sessions in Redis: {len(all_sessions)}")
if all_sessions:
print("\nSession details:")
session = all_sessions[0]
print(f"The stored session: {session}")
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
redis_client | Optional[Redis] | - | Redis client instance to use. If not provided a new client will be created. |
db_url | Optional[str] | - | Redis connection URL (e.g., "redis://localhost:6379/0" or "rediss://user:pass@host:port/db") |
db_prefix | str | "agno" | Prefix for all Redis keys. |
expire | Optional[int] | - | TTL for Redis keys in seconds. |
session_table | Optional[str] | - | Name of the table to store sessions. |
memory_table | Optional[str] | - | Name of the table to store memories. |
metrics_table | Optional[str] | - | Name of the table to store metrics. |
eval_table | Optional[str] | - | Name of the table to store evaluation runs. |
knowledge_table | Optional[str] | - | Name of the table to store knowledge documents. |
traces_table | Optional[str] | - | Name of the table to store traces. |
spans_table | Optional[str] | - | Name of the table to store spans. |