# tq-ngo/redis-go architecture

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

- Interactive diagram: https://gitdiagram.com/tq-ngo/redis-go
- Repository: https://github.com/tq-ngo/redis-go

## Overview

Redis-GO accepts RESP commands over TCP, parses them, executes Redis-style operations, and returns encoded replies. The sampled command-line entry point starts the single-threaded multiplexing server; the repository also documents a multi-threaded Reactor option with I/O handlers and workers. Core capabilities include strings and expiration, sets, sorted sets, Bloom filters, Count-Min Sketch, and eviction. The excerpts show key server dispatch and data-structure implementations, but not all command-to-storage wiring; those uncertain links are omitted or dashed.

Main entry points: [`internal/server/server.go`](https://github.com/tq-ngo/redis-go/blob/main/internal/server/server.go) (TCP server), [`internal/core/executor.go`](https://github.com/tq-ngo/redis-go/blob/main/internal/core/executor.go) (Command executor), [`internal/core/storage.go`](https://github.com/tq-ngo/redis-go/blob/main/internal/core/storage.go) (Core storage), [`internal/server/io_handler.go`](https://github.com/tq-ngo/redis-go/blob/main/internal/server/io_handler.go) (I/O handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_entry["Process entry<br/>[main.go]"]
  node_tcp["TCP server<br/>[server.go]"]
  node_multiplex["I/O multiplexing"]
  node_iohandlers["I/O handlers<br/>[io_handler.go]"]
  node_reactor["Reactor server"]
  node_single["Single listener"]
  node_workers["Command workers<br/>[worker.go]"]
end

subgraph group_protocol["Protocol and commands"]
  node_resp["RESP parser<br/>[resp.go]"]
  node_executor["Command executor<br/>[executor.go]"]
  node_strings["Strings and keys<br/>[worker.go]"]
  node_sets["Set commands<br/>[commands_set.go]"]
  node_sortedcmd["Sorted-set commands"]
  node_bloomcmd["Bloom commands<br/>[command_bf.go]"]
  node_cmscmd["Sketch commands<br/>[command_cms.go]"]
end

subgraph group_storage["Data structures"]
  node_storage[("Core storage<br/>[storage.go]")]
  node_dict["Key dictionary<br/>[dict.go]"]
  node_setdata["Set structure<br/>[simple_set.go]"]
  node_zset["Sorted-set structure<br/>[sortedset.go]"]
  node_skiplist["Skiplist<br/>[skiplist.go]"]
  node_bloom["Bloom filter<br/>[bloom.go]"]
  node_cms["Count-Min Sketch<br/>[cms.go]"]
end

subgraph group_memory["Memory management"]
  node_expire["Expiration<br/>[expire.go]"]
  node_eviction["Eviction policies<br/>[eviction_pool.go]"]
end

node_client(("Redis client"))

node_client -->|"sends commands"| node_tcp
node_entry -->|"starts"| node_tcp
node_tcp -->|"monitors sockets"| node_multiplex
node_tcp -->|"parses input"| node_resp
node_tcp -->|"executes commands"| node_executor
node_tcp -->|"runs active expiry"| node_expire
node_tcp -->|"creates handlers"| node_iohandlers
node_iohandlers -->|"monitors connections"| node_multiplex
node_iohandlers -->|"parses input"| node_resp
node_iohandlers -->|"dispatches tasks"| node_tcp
node_tcp -->|"queues tasks"| node_workers
node_workers -->|"reads and writes"| node_dict
node_executor -.->|"dispatches commands"| node_strings
node_executor -.->|"dispatches commands"| node_sets
node_executor -.->|"dispatches commands"| node_sortedcmd
node_executor -.->|"dispatches commands"| node_bloomcmd
node_executor -.->|"dispatches commands"| node_cmscmd
node_storage -->|"initializes"| node_dict
node_storage -->|"initializes"| node_setdata
node_storage -->|"initializes"| node_zset
node_storage -->|"initializes"| node_bloom
node_storage -->|"initializes"| node_cms
node_zset -.->|"uses index"| node_skiplist
node_expire -.->|"expires keys"| node_dict
node_eviction -.->|"evicts keys"| node_storage
node_reactor -.->|"runs handlers"| node_iohandlers
node_single -.->|"alternative server mode"| node_tcp

click node_entry "https://github.com/tq-ngo/redis-go/blob/main/cmd/main.go"
click node_tcp "https://github.com/tq-ngo/redis-go/blob/main/internal/server/server.go"
click node_multiplex "https://github.com/tq-ngo/redis-go/tree/main/internal/core/io_multiplexing"
click node_iohandlers "https://github.com/tq-ngo/redis-go/blob/main/internal/server/io_handler.go"
click node_reactor "https://github.com/tq-ngo/redis-go/blob/main/internal/server/multi_listeners_server.go"
click node_single "https://github.com/tq-ngo/redis-go/blob/main/internal/server/single_listener_server.go"
click node_workers "https://github.com/tq-ngo/redis-go/blob/main/internal/core/worker.go"
click node_resp "https://github.com/tq-ngo/redis-go/blob/main/internal/core/resp.go"
click node_executor "https://github.com/tq-ngo/redis-go/blob/main/internal/core/executor.go"
click node_strings "https://github.com/tq-ngo/redis-go/blob/main/internal/core/worker.go"
click node_sets "https://github.com/tq-ngo/redis-go/blob/main/internal/core/commands_set.go"
click node_sortedcmd "https://github.com/tq-ngo/redis-go/blob/main/internal/core/commands_sorted_set.go"
click node_bloomcmd "https://github.com/tq-ngo/redis-go/blob/main/internal/core/command_bf.go"
click node_cmscmd "https://github.com/tq-ngo/redis-go/blob/main/internal/core/command_cms.go"
click node_storage "https://github.com/tq-ngo/redis-go/blob/main/internal/core/storage.go"
click node_dict "https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/dict.go"
click node_setdata "https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/simple_set.go"
click node_zset "https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/sortedset.go"
click node_skiplist "https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/skiplist.go"
click node_bloom "https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/bloom.go"
click node_cms "https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/cms.go"
click node_expire "https://github.com/tq-ngo/redis-go/blob/main/internal/core/expire.go"
click node_eviction "https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/eviction_pool.go"

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_entry,node_tcp,node_multiplex,node_iohandlers,node_reactor,node_single,node_workers toneBlue
class node_resp,node_executor,node_strings,node_sets,node_sortedcmd,node_bloomcmd,node_cmscmd,node_client toneAmber
class node_storage,node_dict,node_setdata,node_zset,node_skiplist,node_bloom,node_cms toneMint
class node_expire,node_eviction toneRose
```

## Components

### Server runtime

- [Process entry](https://github.com/tq-ngo/redis-go/blob/main/cmd/main.go): `cmd/main.go`
- [TCP server](https://github.com/tq-ngo/redis-go/blob/main/internal/server/server.go): `internal/server/server.go`
- [I/O multiplexing](https://github.com/tq-ngo/redis-go/tree/main/internal/core/io_multiplexing): `internal/core/io_multiplexing`
- [I/O handlers](https://github.com/tq-ngo/redis-go/blob/main/internal/server/io_handler.go): `internal/server/io_handler.go`
- [Reactor server](https://github.com/tq-ngo/redis-go/blob/main/internal/server/multi_listeners_server.go): `internal/server/multi_listeners_server.go`
- [Single listener](https://github.com/tq-ngo/redis-go/blob/main/internal/server/single_listener_server.go): `internal/server/single_listener_server.go`
- [Command workers](https://github.com/tq-ngo/redis-go/blob/main/internal/core/worker.go): `internal/core/worker.go`

### Protocol and commands

- [RESP parser](https://github.com/tq-ngo/redis-go/blob/main/internal/core/resp.go): `internal/core/resp.go`
- [Command executor](https://github.com/tq-ngo/redis-go/blob/main/internal/core/executor.go): `internal/core/executor.go`
- [Strings and keys](https://github.com/tq-ngo/redis-go/blob/main/internal/core/worker.go): `internal/core/worker.go`
- [Set commands](https://github.com/tq-ngo/redis-go/blob/main/internal/core/commands_set.go): `internal/core/commands_set.go`
- [Sorted-set commands](https://github.com/tq-ngo/redis-go/blob/main/internal/core/commands_sorted_set.go): `internal/core/commands_sorted_set.go`
- [Bloom commands](https://github.com/tq-ngo/redis-go/blob/main/internal/core/command_bf.go): `internal/core/command_bf.go`
- [Sketch commands](https://github.com/tq-ngo/redis-go/blob/main/internal/core/command_cms.go): `internal/core/command_cms.go`

### Data structures

- [Core storage](https://github.com/tq-ngo/redis-go/blob/main/internal/core/storage.go): `internal/core/storage.go`
- [Key dictionary](https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/dict.go): `internal/data_structure/dict.go`
- [Set structure](https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/simple_set.go): `internal/data_structure/simple_set.go`
- [Sorted-set structure](https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/sortedset.go): `internal/data_structure/sortedset.go`
- [Skiplist](https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/skiplist.go): `internal/data_structure/skiplist.go`
- [Bloom filter](https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/bloom.go): `internal/data_structure/bloom.go`
- [Count-Min Sketch](https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/cms.go): `internal/data_structure/cms.go`

### Memory management

- [Expiration](https://github.com/tq-ngo/redis-go/blob/main/internal/core/expire.go): `internal/core/expire.go`
- [Eviction policies](https://github.com/tq-ngo/redis-go/blob/main/internal/data_structure/eviction_pool.go): `internal/data_structure/eviction_pool.go`

### Other components

- **Redis client**

## Connections

- Redis client → TCP server: sends commands (evidence: `README.md`)
- Process entry → TCP server: starts (evidence: `cmd/main.go`)
- TCP server → I/O multiplexing: monitors sockets (evidence: `internal/server/server.go`)
- TCP server → RESP parser: parses input (evidence: `internal/server/server.go`)
- TCP server → Command executor: executes commands (evidence: `internal/server/server.go`)
- TCP server → Expiration: runs active expiry (evidence: `internal/server/server.go`)
- TCP server → I/O handlers: creates handlers (evidence: `internal/server/server.go`)
- I/O handlers → I/O multiplexing: monitors connections (evidence: `internal/server/io_handler.go`)
- I/O handlers → RESP parser: parses input (evidence: `internal/server/io_handler.go`)
- I/O handlers → TCP server: dispatches tasks (evidence: `internal/server/io_handler.go`)
- TCP server → Command workers: queues tasks (evidence: `internal/server/server.go`)
- Command workers → Key dictionary: reads and writes (evidence: `internal/core/worker.go`)
- Command executor → Strings and keys: dispatches commands
- Command executor → Set commands: dispatches commands
- Command executor → Sorted-set commands: dispatches commands
- Command executor → Bloom commands: dispatches commands
- Command executor → Sketch commands: dispatches commands
- Core storage → Key dictionary: initializes (evidence: `internal/core/storage.go`)
- Core storage → Set structure: initializes (evidence: `internal/core/storage.go`)
- Core storage → Sorted-set structure: initializes (evidence: `internal/core/storage.go`)
- Core storage → Bloom filter: initializes (evidence: `internal/core/storage.go`)
- Core storage → Count-Min Sketch: initializes (evidence: `internal/core/storage.go`)
- Sorted-set structure → Skiplist: uses index
- Expiration → Key dictionary: expires keys
- Eviction policies → Core storage: evicts keys
- Reactor server → I/O handlers: runs handlers
- Single listener → TCP server: alternative server mode
