How tq-ngo/redis-go works
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: server.go TCP server · executor.go Command executor · storage.go Core storage · io_handler.go I/O handlers
Components 24
Server runtime
- Process entry
cmd/main.go - TCP server
internal/server/server.go - I/O multiplexing
internal/core/io_multiplexing - I/O handlers
internal/server/io_handler.go - Reactor server
internal/server/multi_listeners_server.go - Single listener
internal/server/single_listener_server.go - Command workers
internal/core/worker.go
Protocol and commands
- RESP parser
internal/core/resp.go - Command executor
internal/core/executor.go - Strings and keys
internal/core/worker.go - Set commands
internal/core/commands_set.go - Sorted-set commands
internal/core/commands_sorted_set.go - Bloom commands
internal/core/command_bf.go - Sketch commands
internal/core/command_cms.go
Data structures
- Core storage
internal/core/storage.go - Key dictionary
internal/data_structure/dict.go - Set structure
internal/data_structure/simple_set.go - Sorted-set structure
internal/data_structure/sortedset.go - Skiplist
internal/data_structure/skiplist.go - Bloom filter
internal/data_structure/bloom.go - Count-Min Sketch
internal/data_structure/cms.go
Memory management
- Expiration
internal/core/expire.go - Eviction policies
internal/data_structure/eviction_pool.go
Other components
- Redis client
Connections 27
- Redis client → TCP server: sends commands
README.md - Process entry → TCP server: starts
cmd/main.go - TCP server → I/O multiplexing: monitors sockets
internal/server/server.go - TCP server → RESP parser: parses input
internal/server/server.go - TCP server → Command executor: executes commands
internal/server/server.go - TCP server → Expiration: runs active expiry
internal/server/server.go - TCP server → I/O handlers: creates handlers
internal/server/server.go - I/O handlers → I/O multiplexing: monitors connections
internal/server/io_handler.go - I/O handlers → RESP parser: parses input
internal/server/io_handler.go - I/O handlers → TCP server: dispatches tasks
internal/server/io_handler.go - TCP server → Command workers: queues tasks
internal/server/server.go - Command workers → Key dictionary: reads and writes
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
internal/core/storage.go - Core storage → Set structure: initializes
internal/core/storage.go - Core storage → Sorted-set structure: initializes
internal/core/storage.go - Core storage → Bloom filter: initializes
internal/core/storage.go - Core storage → Count-Min Sketch: initializes
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