# cunla/fakeredis-py architecture

> Architecture diagram of the GitHub repository cunla/fakeredis-py, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cunla/fakeredis-py
- Repository: https://github.com/cunla/fakeredis-py

## Overview

fakeredis is an in-memory, pure-Python Redis-compatible client/server emulator. A caller uses its synchronous or asynchronous client API; commands are handled by the fake server and update shared in-memory database state, with replies returned through the socket/protocol layer. The documented surface also includes server-specific behavior and Redis Stack command families. The tree and excerpts support the main components and data models, but do not show all client-to-server dispatch details, so uncertain wiring is omitted.

Main entry points: [`fakeredis/commands_mixins`](https://github.com/cunla/fakeredis-py/tree/master/fakeredis/commands_mixins) (Core Commands), [`fakeredis/_core/_database.py`](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_core/_database.py) (Key Database), [`fakeredis/_clients/_base.py`](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_base.py) (Client Connection), [`fakeredis/_clients/_sync.py`](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_sync.py) (Sync Clients)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client APIs"]
  node_sync["Sync Clients<br/>[_sync.py]"]
  node_async["Async Clients<br/>[_async.py]"]
end

subgraph group_runtime["Protocol Runtime"]
  node_server["Fake Server<br/>[_server.py]"]
  node_connection["Client Connection<br/>[_base.py]"]
  node_socket["Fake Sockets"]
  node_resp["RESP Protocol<br/>[_resp.py]"]
  node_tcp["TCP Adapter<br/>[_tcp_server.py]"]
end

subgraph group_commands["Command Emulation"]
  node_dispatch["Command Dispatch<br/>[_commands.py]"]
  node_corecommands["Core Commands"]
  node_transactions["Transactions"]
  node_pubsub["Pub/Sub<br/>[pubsub_mixin.py]"]
end

subgraph group_state["In-Memory State"]
  node_database[("Key Database<br/>[_database.py]")]
  node_models["Value Models"]
  node_streams["Stream Model<br/>[_stream.py]"]
end

subgraph group_extensions["Server Extensions"]
  node_stack["Stack Commands"]
  node_dragonfly["Dragonfly Commands<br/>[dragonfly_mixin.py]"]
  node_geo["Geo Utilities"]
  node_valkey["Valkey Support<br/>[_valkey.py]"]
end

node_caller(("Application"))

node_caller -->|"uses API"| node_sync
node_caller -->|"uses API"| node_async
node_sync -->|"creates connection"| node_connection
node_async -->|"creates connection"| node_connection
node_connection -->|"executes commands"| node_server
node_connection -->|"uses socket"| node_socket
node_socket -->|"encodes replies"| node_resp
node_server -->|"dispatches commands"| node_dispatch
node_dispatch -->|"selects handler"| node_corecommands
node_corecommands -->|"reads and writes"| node_database
node_corecommands -->|"uses values"| node_models
node_corecommands -->|"uses streams"| node_streams
node_transactions -->|"watches keys"| node_database
node_pubsub -->|"notifies changes"| node_database
node_stack -->|"stores values"| node_database
node_stack -->|"uses models"| node_models
node_dragonfly -->|"updates state"| node_database
node_dragonfly -->|"uses models"| node_models
node_geo -->|"supports geo"| node_corecommands
node_tcp -.->|"hosts server"| node_server
node_valkey -.->|"extends compatibility"| node_sync

click node_sync "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_sync.py"
click node_async "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_async.py"
click node_server "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_core/_server.py"
click node_connection "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_base.py"
click node_socket "https://github.com/cunla/fakeredis-py/tree/master/fakeredis/_socket"
click node_resp "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_socket/_resp.py"
click node_tcp "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_tcp_server.py"
click node_dispatch "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_commands.py"
click node_corecommands "https://github.com/cunla/fakeredis-py/tree/master/fakeredis/commands_mixins"
click node_transactions "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/commands_mixins/transactions_mixin.py"
click node_pubsub "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/commands_mixins/pubsub_mixin.py"
click node_stack "https://github.com/cunla/fakeredis-py/tree/master/fakeredis/stack"
click node_dragonfly "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/server_specific_commands/dragonfly_mixin.py"
click node_database "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_core/_database.py"
click node_models "https://github.com/cunla/fakeredis-py/tree/master/fakeredis/model"
click node_streams "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/model/_stream.py"
click node_geo "https://github.com/cunla/fakeredis-py/tree/master/fakeredis/geo"
click node_valkey "https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_valkey.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sync,node_async toneBlue
class node_server,node_connection,node_socket,node_resp,node_tcp toneAmber
class node_dispatch,node_corecommands,node_transactions,node_pubsub toneMint
class node_database,node_models,node_streams toneRose
class node_stack,node_dragonfly,node_geo,node_valkey,node_caller toneIndigo
```

## Components

### Client APIs

- [Sync Clients](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_sync.py): `fakeredis/_clients/_sync.py`
- [Async Clients](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_async.py): `fakeredis/_clients/_async.py`

### Protocol Runtime

- [Fake Server](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_core/_server.py): `fakeredis/_core/_server.py`
- [Client Connection](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_base.py): `fakeredis/_clients/_base.py`
- [Fake Sockets](https://github.com/cunla/fakeredis-py/tree/master/fakeredis/_socket): `fakeredis/_socket`
- [RESP Protocol](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_socket/_resp.py): `fakeredis/_socket/_resp.py`
- [TCP Adapter](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_tcp_server.py): `fakeredis/_clients/_tcp_server.py`

### Command Emulation

- [Command Dispatch](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_commands.py): `fakeredis/_commands.py`
- [Core Commands](https://github.com/cunla/fakeredis-py/tree/master/fakeredis/commands_mixins): `fakeredis/commands_mixins`
- [Transactions](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/commands_mixins/transactions_mixin.py): `fakeredis/commands_mixins/transactions_mixin.py`
- [Pub/Sub](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/commands_mixins/pubsub_mixin.py): `fakeredis/commands_mixins/pubsub_mixin.py`

### In-Memory State

- [Key Database](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_core/_database.py): `fakeredis/_core/_database.py`
- [Value Models](https://github.com/cunla/fakeredis-py/tree/master/fakeredis/model): `fakeredis/model`
- [Stream Model](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/model/_stream.py): `fakeredis/model/_stream.py`

### Server Extensions

- [Stack Commands](https://github.com/cunla/fakeredis-py/tree/master/fakeredis/stack): `fakeredis/stack`
- [Dragonfly Commands](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/server_specific_commands/dragonfly_mixin.py): `fakeredis/server_specific_commands/dragonfly_mixin.py`
- [Geo Utilities](https://github.com/cunla/fakeredis-py/tree/master/fakeredis/geo): `fakeredis/geo`
- [Valkey Support](https://github.com/cunla/fakeredis-py/blob/master/fakeredis/_clients/_valkey.py): `fakeredis/_clients/_valkey.py`

### Other components

- **Application**

## Connections

- Application → Sync Clients: uses API
- Application → Async Clients: uses API
- Sync Clients → Client Connection: creates connection
- Async Clients → Client Connection: creates connection
- Client Connection → Fake Server: executes commands
- Client Connection → Fake Sockets: uses socket
- Fake Sockets → RESP Protocol: encodes replies
- Fake Server → Command Dispatch: dispatches commands
- Command Dispatch → Core Commands: selects handler
- Core Commands → Key Database: reads and writes
- Core Commands → Value Models: uses values
- Core Commands → Stream Model: uses streams
- Transactions → Key Database: watches keys
- Pub/Sub → Key Database: notifies changes
- Stack Commands → Key Database: stores values
- Stack Commands → Value Models: uses models
- Dragonfly Commands → Key Database: updates state
- Dragonfly Commands → Value Models: uses models
- Geo Utilities → Core Commands: supports geo
- TCP Adapter → Fake Server: hosts server
- Valkey Support → Sync Clients: extends compatibility
