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

# RedisStorage

> Redis storage for distributed and high-performance systems

## Overview

`RedisStorage` provides a Redis-based storage backend. Ideal for distributed systems, high-performance requirements, and applications needing TTL-based expiration.

## Install

<Note>
  Install the Redis storage optional dependency group:

  ```bash theme={null}
  uv pip install "upsonic[redis-storage]"
  ```
</Note>

## Basic Usage

```python theme={null}
from upsonic import Agent, Task
from upsonic.storage.memory import Memory
from upsonic.storage.redis import RedisStorage

storage = RedisStorage(
    db_url="redis://localhost:6379/0",
    db_prefix="myapp",
    expire=86400  # 24 hours TTL
)

memory = Memory(
    storage=storage,
    session_id="session_001",
    user_id="user_123",
    full_session_memory=True,
    summary_memory=True,
    user_analysis_memory=True,
    model="anthropic/claude-sonnet-4-5"
)

agent = Agent("anthropic/claude-sonnet-4-5", memory=memory)

result1 = agent.do(Task("My name is Alice"))
result2 = agent.do(Task("What's my name?"))
print(result2)  # "Your name is Alice"
```

## Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `db_url` | `str \| None` | `None` | Redis connection URL (e.g., `redis://localhost:6379/0`) |
| `redis_client` | `Redis \| RedisCluster \| None` | `None` | Pre-existing Redis client |
| `db_prefix` | `str` | `"upsonic"` | Prefix for all Redis keys |
| `expire` | `int \| None` | `None` | TTL in seconds for all keys |
| `session_table` | `str \| None` | `"sessions"` | Session key namespace |
| `user_memory_table` | `str \| None` | `"user_memories"` | User memory key namespace |
| `knowledge_table` | `str \| None` | `"upsonic_knowledge"` | Knowledge registry key namespace (used by KnowledgeBase) |
| `id` | `str \| None` | auto-generated | Storage instance ID |

## Storage Type

`RedisStorage` is a **synchronous** storage implementation. For Redis Cluster support, provide a pre-configured `RedisCluster` client.

## Key Structure

Keys are structured as: `{db_prefix}:{table}:{id}`

Example: `myapp:sessions:session_001`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.