# microsoftarchive/redis architecture

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

- Interactive diagram: https://gitdiagram.com/microsoftarchive/redis
- Repository: https://github.com/microsoftarchive/redis

## Overview

This repository is a Windows port of the Redis in-memory data store. The main workflow is a client sending commands to the server, which executes them against Redis data structures and returns replies; separate subsystems cover persistence, replication, clustering, scripting, and monitoring. Windows-specific layers provide service hosting, process behavior, and virtual file descriptors. The README documents Windows service support, the fork replacement, jemalloc, and descriptor mapping. Several runtime sources were not sampled, so unverified internal calls are omitted or shown as dashed, unevidenced relationships.

Main entry points: [`src/redis.c`](https://github.com/microsoftarchive/redis/blob/3.0/src/redis.c) (Server runtime), [`src/db.c`](https://github.com/microsoftarchive/redis/blob/3.0/src/db.c) (Command execution), [`src/networking.c`](https://github.com/microsoftarchive/redis/blob/3.0/src/networking.c) (Command networking), [`src/sentinel.c`](https://github.com/microsoftarchive/redis/blob/3.0/src/sentinel.c) (Sentinel monitoring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Redis Server"]
  node_server_main["Server runtime<br/>[redis.c]"]
  node_network["Command networking<br/>[networking.c]"]
  node_commands["Command execution<br/>[db.c]"]
  node_blocked["Blocked clients<br/>[blocked.c]"]
  node_pubsub["Publish subscribe<br/>[pubsub.c]"]
  node_scripting["Lua scripting<br/>[scripting.c]"]
  node_lua_runtime["Lua runtime"]
end

subgraph group_data["Data and Persistence"]
  node_data_types["Data structures"]
  node_rdb["RDB persistence<br/>[rdb.c]"]
  node_aof["AOF persistence<br/>[aof.c]"]
end

subgraph group_distributed["Distributed Redis"]
  node_replication["Replication<br/>[replication.c]"]
  node_cluster["Cluster management<br/>[cluster.c]"]
  node_sentinel["Sentinel monitoring<br/>[sentinel.c]"]
end

subgraph group_windows["Windows Runtime"]
  node_service["Windows service host<br/>[Win32_service.cpp]"]
  node_fd_mapping["Virtual descriptors<br/>[Win32_FDAPI.h]"]
  node_win_process["Process emulation<br/>[Win32_QFork.cpp]"]
  node_allocator["jemalloc allocator<br/>[arena.c]"]
end

subgraph group_clients["Client Tools"]
  node_cli["Redis CLI<br/>[redis-cli.c]"]
  node_line_editor["Interactive input<br/>[linenoise.c]"]
  node_hiredis["Redis client library<br/>[hiredis.c]"]
  node_async_client["Async client API<br/>[async.c]"]
end

node_client(("Redis clients"))

node_client -.->|"sends commands"| node_network
node_network -.->|"dispatches"| node_commands
node_commands -.->|"uses structures"| node_data_types
node_commands -.->|"checks waiters"| node_blocked
node_commands -.->|"routes messages"| node_pubsub
node_server_main -.->|"runs service"| node_network
node_server_main -.->|"coordinates saves"| node_rdb
node_server_main -.->|"coordinates logging"| node_aof
node_server_main -.->|"coordinates replication"| node_replication
node_server_main -.->|"coordinates cluster"| node_cluster
node_server_main -.->|"runs scripts"| node_scripting
node_scripting -.->|"embeds runtime"| node_lua_runtime
node_cluster -->|"uses server definitions"| node_server_main
node_sentinel -->|"uses client API"| node_hiredis
node_sentinel -->|"uses async API"| node_async_client
node_cli -.->|"reads input"| node_line_editor
node_cli -.->|"sends commands"| node_hiredis
node_service -->|"calls main"| node_server_main
node_server_main -->|"uses descriptor layer"| node_fd_mapping
node_server_main -.->|"uses fork replacement"| node_win_process
node_server_main -.->|"allocates memory"| node_allocator

click node_server_main "https://github.com/microsoftarchive/redis/blob/3.0/src/redis.c"
click node_network "https://github.com/microsoftarchive/redis/blob/3.0/src/networking.c"
click node_commands "https://github.com/microsoftarchive/redis/blob/3.0/src/db.c"
click node_blocked "https://github.com/microsoftarchive/redis/blob/3.0/src/blocked.c"
click node_pubsub "https://github.com/microsoftarchive/redis/blob/3.0/src/pubsub.c"
click node_data_types "https://github.com/microsoftarchive/redis/tree/3.0/src"
click node_rdb "https://github.com/microsoftarchive/redis/blob/3.0/src/rdb.c"
click node_aof "https://github.com/microsoftarchive/redis/blob/3.0/src/aof.c"
click node_replication "https://github.com/microsoftarchive/redis/blob/3.0/src/replication.c"
click node_cluster "https://github.com/microsoftarchive/redis/blob/3.0/src/cluster.c"
click node_sentinel "https://github.com/microsoftarchive/redis/blob/3.0/src/sentinel.c"
click node_scripting "https://github.com/microsoftarchive/redis/blob/3.0/src/scripting.c"
click node_lua_runtime "https://github.com/microsoftarchive/redis/tree/3.0/deps/lua/src"
click node_service "https://github.com/microsoftarchive/redis/blob/3.0/src/Win32_Interop/Win32_service.cpp"
click node_fd_mapping "https://github.com/microsoftarchive/redis/blob/3.0/src/Win32_Interop/Win32_FDAPI.h"
click node_win_process "https://github.com/microsoftarchive/redis/blob/3.0/src/Win32_Interop/Win32_QFork.cpp"
click node_allocator "https://github.com/microsoftarchive/redis/blob/3.0/deps/jemalloc-win/src/arena.c"
click node_cli "https://github.com/microsoftarchive/redis/blob/3.0/src/redis-cli.c"
click node_line_editor "https://github.com/microsoftarchive/redis/blob/3.0/deps/linenoise/linenoise.c"
click node_hiredis "https://github.com/microsoftarchive/redis/blob/3.0/deps/hiredis/hiredis.c"
click node_async_client "https://github.com/microsoftarchive/redis/blob/3.0/deps/hiredis/async.c"

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_server_main,node_network,node_commands,node_blocked,node_pubsub,node_scripting,node_lua_runtime toneBlue
class node_data_types,node_rdb,node_aof,node_client toneAmber
class node_replication,node_cluster,node_sentinel toneMint
class node_service,node_fd_mapping,node_win_process,node_allocator toneRose
class node_cli,node_line_editor,node_hiredis,node_async_client toneIndigo
```

## Components

### Redis Server

- [Server runtime](https://github.com/microsoftarchive/redis/blob/3.0/src/redis.c): `src/redis.c`
- [Command networking](https://github.com/microsoftarchive/redis/blob/3.0/src/networking.c): `src/networking.c`
- [Command execution](https://github.com/microsoftarchive/redis/blob/3.0/src/db.c): `src/db.c`
- [Blocked clients](https://github.com/microsoftarchive/redis/blob/3.0/src/blocked.c): `src/blocked.c`
- [Publish subscribe](https://github.com/microsoftarchive/redis/blob/3.0/src/pubsub.c): `src/pubsub.c`
- [Lua scripting](https://github.com/microsoftarchive/redis/blob/3.0/src/scripting.c): `src/scripting.c`
- [Lua runtime](https://github.com/microsoftarchive/redis/tree/3.0/deps/lua/src): `deps/lua/src`

### Data and Persistence

- [Data structures](https://github.com/microsoftarchive/redis/tree/3.0/src): `src`
- [RDB persistence](https://github.com/microsoftarchive/redis/blob/3.0/src/rdb.c): `src/rdb.c`
- [AOF persistence](https://github.com/microsoftarchive/redis/blob/3.0/src/aof.c): `src/aof.c`

### Distributed Redis

- [Replication](https://github.com/microsoftarchive/redis/blob/3.0/src/replication.c): `src/replication.c`
- [Cluster management](https://github.com/microsoftarchive/redis/blob/3.0/src/cluster.c): `src/cluster.c`
- [Sentinel monitoring](https://github.com/microsoftarchive/redis/blob/3.0/src/sentinel.c): `src/sentinel.c`

### Windows Runtime

- [Windows service host](https://github.com/microsoftarchive/redis/blob/3.0/src/Win32_Interop/Win32_service.cpp): `src/Win32_Interop/Win32_service.cpp`
- [Virtual descriptors](https://github.com/microsoftarchive/redis/blob/3.0/src/Win32_Interop/Win32_FDAPI.h): `src/Win32_Interop/Win32_FDAPI.h`
- [Process emulation](https://github.com/microsoftarchive/redis/blob/3.0/src/Win32_Interop/Win32_QFork.cpp): `src/Win32_Interop/Win32_QFork.cpp`
- [jemalloc allocator](https://github.com/microsoftarchive/redis/blob/3.0/deps/jemalloc-win/src/arena.c): `deps/jemalloc-win/src/arena.c`

### Client Tools

- [Redis CLI](https://github.com/microsoftarchive/redis/blob/3.0/src/redis-cli.c): `src/redis-cli.c`
- [Interactive input](https://github.com/microsoftarchive/redis/blob/3.0/deps/linenoise/linenoise.c): `deps/linenoise/linenoise.c`
- [Redis client library](https://github.com/microsoftarchive/redis/blob/3.0/deps/hiredis/hiredis.c): `deps/hiredis/hiredis.c`
- [Async client API](https://github.com/microsoftarchive/redis/blob/3.0/deps/hiredis/async.c): `deps/hiredis/async.c`

### Other components

- **Redis clients**

## Connections

- Redis clients → Command networking: sends commands
- Command networking → Command execution: dispatches
- Command execution → Data structures: uses structures
- Command execution → Blocked clients: checks waiters
- Command execution → Publish subscribe: routes messages
- Server runtime → Command networking: runs service
- Server runtime → RDB persistence: coordinates saves
- Server runtime → AOF persistence: coordinates logging
- Server runtime → Replication: coordinates replication
- Server runtime → Cluster management: coordinates cluster
- Server runtime → Lua scripting: runs scripts
- Lua scripting → Lua runtime: embeds runtime
- Cluster management → Server runtime: uses server definitions (evidence: `src/cluster.c`)
- Sentinel monitoring → Redis client library: uses client API (evidence: `src/sentinel.c`)
- Sentinel monitoring → Async client API: uses async API (evidence: `src/sentinel.c`)
- Redis CLI → Interactive input: reads input
- Redis CLI → Redis client library: sends commands
- Windows service host → Server runtime: calls main (evidence: `src/Win32_Interop/Win32_service.cpp`)
- Server runtime → Virtual descriptors: uses descriptor layer
- Server runtime → Process emulation: uses fork replacement
- Server runtime → jemalloc allocator: allocates memory
