> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Redis for Agent

> Store agent sessions and run history in Redis with RedisDb.

`RedisDb` stores an Agent's sessions and run history in Redis.

## Usage

Install dependencies:

```shell theme={null}
uv pip install agno redis openai ddgs
```

Export your OpenAI API key:

<CodeGroup>
  ```bash Mac/Linux theme={null}
  export OPENAI_API_KEY="your_openai_api_key_here"
  ```

  ```powershell Windows theme={null}
  $Env:OPENAI_API_KEY="your_openai_api_key_here"
  ```
</CodeGroup>

### Run Redis

Install [Docker Desktop](https://docs.docker.com/get-started/get-docker/), then start Redis on port `6379`:

```bash theme={null}
docker run -d \
  --name my-redis \
  -p 6379:6379 \
  redis
```

```python redis_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.base import SessionType
from agno.db.redis import RedisDb
from agno.tools.websearch import WebSearchTools

db = RedisDb(db_url="redis://localhost:6379")

agent = Agent(
    db=db,
    tools=[WebSearchTools()],
    add_history_to_context=True,
)

agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")

all_sessions = db.get_sessions(session_type=SessionType.AGENT)
print(f"Stored sessions: {len(all_sessions)}")

if all_sessions:
    print(all_sessions[0])
```

## Parameters

<Snippet file="db-redis-params.mdx" />
