# wiqer/ef-redis architecture

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

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

## Overview

##### Project type and purpose
- EF-Redis is a standalone Java implementation of a Redis server, built on top of Netty.
- It accepts Redis (RESP) protocol commands over TCP, executes them against an in-memory data store, appends operations to an AOF log, and returns RESP-encoded replies.

##### File structure
- Top‐level: pom.xml, src/main/java/com/wiqer/redis, src/main/resources, src/test
- com.wiqer.redis: entry point (MyRedisServer, RedisServer), networking (channel/…/ChannelOption, netty/channel/…), protocol (resp/*, CommandDecoder, ResponseEncoder), core logic (RedisCoreImpl, CommandHandler, command/impl/*), data types (RedisData, RedisString, RedisList…), persistence (aof/Aof, RingBlockingQueue), utilities, configs.
- Patterns:
- Netty pipeline pattern (decoder → handler → encoder)
- Strategy pattern (ChannelSelectStrategy + multiple ChannelOption implementations)
- Command factory + command hierarchy (CommandFactory, Command and impl/*)
- Single-threaded vs multi-threaded event loops

##### README for additional insights
- Server startup via MyRedisServer using Java+Netty
- Supports only AOF persistence and basic five data types
- Recommends single‐threaded select model for best performance
- External clients: redis-client, redis-desktop

##### Detail
- Every major package or logical module as a distinct component.
- Both synchronous flow (command handling) and asynchronous flow (AOF queue).
- Strategy pattern decision point for ChannelOption selection.
- Configuration loading at startup.

## Diagram (Mermaid)

```mermaid
graph TD

    subgraph "External Clients"
        Client["Redis Client"]:::clients
    end

    subgraph "Networking"
        MyRedisServer["MyRedisServer"]:::network
        RedisServer["RedisServer"]:::network
        ServerBootstrap["ServerBootstrap"]:::network
    end

    Client -->|"sends TCP bytes"| ServerBootstrap
    MyRedisServer --> RedisServer
    RedisServer --> ServerBootstrap

    click MyRedisServer "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/MyRedisServer.java"
    click RedisServer "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/RedisServer.java"

    subgraph "Channel Select Strategy"
        Strategy["ChannelSelectStrategy"]:::strategy
        DefaultStrategy["DefaultChannelSelectStrategy"]:::strategy
        EpollOption["EpollChannelOption"]:::strategy
        KqueueOption["KqueueChannelOption"]:::strategy
        NioSelectOption["NioSelectChannelOption"]:::strategy
        SingleSelect["SingleSelectChannelOption"]:::strategy
        NettySingle["NettySingleSelectChannelOption"]:::strategy
        LocalOption["DefaultChannelOption"]:::strategy
    end

    ServerBootstrap --> Strategy
    Strategy --> DefaultStrategy
    DefaultStrategy --> EpollOption
    DefaultStrategy --> KqueueOption
    DefaultStrategy --> NioSelectOption
    DefaultStrategy --> SingleSelect
    DefaultStrategy --> NettySingle
    DefaultStrategy --> LocalOption

    click Strategy "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/ChannelSelectStrategy.java"
    click DefaultStrategy "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/DefaultChannelSelectStrategy.java"
    click EpollOption "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/epoll/EpollChannelOption.java"
    click KqueueOption "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/kqueue/KqueueChannelOption.java"
    click NioSelectOption "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/select/NioSelectChannelOption.java"
    click SingleSelect "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/single/SingleSelectChannelOption.java"
    click NettySingle "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/single/NettySingleSelectChannelOption.java"
    click LocalOption "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/channel/local/DefaultChannelOption.java"

    subgraph "EventLoopGroups"
        SingleELG["SingleThreadEventLoopGroup"]:::thread
        NioELG["NioSingleEventLoopGroup"]:::thread
    end

    ServerBootstrap --> SingleELG
    ServerBootstrap --> NioELG

    click SingleELG "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/netty/channel/SingleThreadEventLoopGroup.java"
    click NioELG "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/netty/channel/nio/NioSingleEventLoopGroup.java"

    subgraph "NIO Channels"
        AbstractNioByte["AbstractSingleNioByteChannel"]:::thread
        AbstractNio["AbstractSingleNioChannel"]:::thread
        NioServerChannel["NioSingleServerSocketChannel"]:::thread
        NioSocketChannel["NioSingleSocketChannel"]:::thread
    end

    NioELG --> AbstractNio
    NioELG --> AbstractNioByte
    AbstractNio --> NioServerChannel
    AbstractNioByte --> NioSocketChannel

    click AbstractNioByte "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/netty/channel/nio/AbstractSingleNioByteChannel.java"
    click AbstractNio "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/netty/channel/nio/AbstractSingleNioChannel.java"
    click NioServerChannel "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/netty/channel/socket/NioSingleServerSocketChannel.java"
    click NioSocketChannel "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/netty/channel/socket/NioSingleSocketChannel.java"

    subgraph "Netty Pipeline"
        Decoder["CommandDecoder"]:::protocol
        Handler["CommandHandler"]:::protocol
        Encoder["ResponseEncoder"]:::protocol
    end

    NioSocketChannel --> Decoder
    Decoder --> Handler
    Handler --> Encoder
    Encoder --> Client

    click Decoder "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/CommandDecoder.java"
    click Handler "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/CommandHandler.java"
    click Encoder "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/ResponseEncoder.java"

    subgraph "Core"
        RedisCore["RedisCoreImpl"]:::core
        CommandFactory["CommandFactory"]:::core
        CommandInterface["Command"]:::core
    end

    Handler -->|"dispatches"| CommandFactory
    CommandFactory --> CommandInterface
    CommandInterface --> RedisCore

    click CommandFactory "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/command/CommandFactory.java"
    click CommandInterface "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/command/Command.java"
    click RedisCore "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/RedisCoreImpl.java"

    subgraph "Data Types"
        StringDT["RedisString"]:::core
        ListDT["RedisList"]:::core
        SetDT["RedisSet"]:::core
        HashDT["RedisHash"]:::core
        ZsetDT["RedisZset"]:::core
        BytesWrapper["BytesWrapper"]:::core
    end

    RedisCore --> StringDT
    RedisCore --> ListDT
    RedisCore --> SetDT
    RedisCore --> HashDT
    RedisCore --> ZsetDT
    RedisCore --> BytesWrapper

    click StringDT "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/datatype/RedisString.java"
    click ListDT "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/datatype/RedisList.java"
    click SetDT "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/datatype/RedisSet.java"
    click HashDT "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/datatype/RedisHash.java"
    click ZsetDT "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/datatype/RedisZset.java"
    click BytesWrapper "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/datatype/BytesWrapper.java"

    subgraph "AOF Persistence"
        Queue["RingBlockingQueue"]:::persistence
        Aof["Aof"]:::persistence
        Disk["AOF File"]:::persistence
    end

    RedisCore --> Queue
    Queue --> Aof
    Aof --> Disk

    click Queue "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/aof/RingBlockingQueue.java"
    click Aof "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/aof/Aof.java"

    subgraph "Configuration"
        PropertiesUtil["PropertiesUtil"]:::config
        ConfFile["redis_conf.properties"]:::config
    end

    MyRedisServer --> PropertiesUtil
    PropertiesUtil --> ConfFile

    click PropertiesUtil "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/util/PropertiesUtil.java"

    subgraph "RESP Protocol Models"
        RespType["Resp"]:::protocol
        RespArray["RespArray"]:::protocol
        RespInt["RespInt"]:::protocol
        SimpleStr["SimpleString"]:::protocol
        BulkStr["BulkString"]:::protocol
        Errors["Errors"]:::protocol
        TypeEnum["RespType"]:::protocol
    end

    Decoder --> RespType
    Decoder --> RespArray
    Decoder --> RespInt
    Decoder --> SimpleStr
    Decoder --> BulkStr
    Decoder --> Errors
    Decoder --> TypeEnum

    click RespType "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/resp/Resp.java"
    click RespArray "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/resp/RespArray.java"
    click RespInt "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/resp/RespInt.java"
    click SimpleStr "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/resp/SimpleString.java"
    click BulkStr "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/resp/BulkString.java"
    click Errors "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/resp/Errors.java"
    click TypeEnum "https://github.com/wiqer/ef-redis/blob/master/src/main/java/com/wiqer/redis/resp/RespType.java"

    subgraph "Utilities"
        StringUtil["StringUtil"]:::util
        Format["Format"]:::util
        Uid["Uid"]:::util
        WinterId["WinterId"]:::util
        TraceId["TRACEID"]:::util
    end

    PropertiesUtil --> StringUtil
    Handler --> TraceId

    classDef clients fill:#f9f,stroke:#333,stroke-width:1px
    classDef network fill:#bbf,stroke:#333,stroke-width:1px
    classDef strategy fill:#bbf,stroke:#333,stroke-width:1px
    classDef thread fill:#bbf,stroke:#333,stroke-width:1px
    classDef protocol fill:#bfb,stroke:#333,stroke-width:1px
    classDef core fill:#fb8,stroke:#333,stroke-width:1px
    classDef persistence fill:#f88,stroke:#333,stroke-width:1px
    classDef config fill:#ccc,stroke:#333,stroke-width:1px
    classDef util fill:#ddd,stroke:#333,stroke-width:1px
```
