[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-75434":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":16,"starSnapshotCount":16,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},75434,"ConcurrentCache","zimingttkx\u002FConcurrentCache","zimingttkx"," A high-performance distributed in-memory object cache system built from scratch in C++17, compatible with Redis protocol.","",null,"C++",173,7,5,1,0,8,39,24,66.61,"MIT License",false,"main",true,[26,27,28,29,30,31],"concurrency","cplusplus","high-performance","in-memoty-database","network-programming","redis-cache","2026-06-12 04:01:18","# ConcurrentCache\n\n**C++ 高性能内存缓存系统 | Redis RESP 协议兼容**\n\n[![C++20](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FC%2B%2B-20-blue.svg)](https:\u002F\u002Fen.cppreference.com\u002F)\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-green.svg)](LICENSE)\n[![Build](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Factions\u002Fworkflow\u002Fstatus\u002Fdingziming\u002FConcurrentCache\u002Fci.yml?style=flat-square)](https:\u002F\u002Fgithub.com\u002Fdingziming\u002FConcurrentCache\u002Factions)\n[![Docker](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDocker-ghcr.io-blue.svg)](https:\u002F\u002Fgithub.com\u002Fdingziming\u002FConcurrentCache\u002Fpkgs\u002Fcontainer\u002Fconcurrentcache)\n\n## 简介\n\nConcurrentCache 是纯 C++20 实现的内存对象缓存系统，兼容 Redis RESP 协议，支持 `redis-cli` 及任意 Redis 客户端连接操作。\n\n本项目旨在通过从零实现，深入理解 Linux 高性能网络编程、并发控制、缓存系统设计等核心技术。\n\n## 核心特性\n\n| 特性 | 说明 |\n|------|------|\n| 高性能网络模型 | MainReactor + SubReactorPool 多线程 Reactor 架构，epoll 多路复用 |\n| 线程安全存储 | 64 分片分段锁哈希表，降低锁竞争 |\n| 高效内存管理 | ThreadCache（无锁）→ CentralCache（细粒度锁）→ PageCache 三层架构 |\n| 协议兼容 | 支持 STRING\u002FLIST\u002FHASH\u002FSET\u002FZSET 五种数据类型 |\n| 持久化 | RDB 快照，Fork\u002FCOW 机制，服务重启自动恢复 |\n| 集群支持 | V4.0 支持哈希槽分片、Gossip 协议、主从复制 |\n\n## 技术规格\n\n| 项目 | 规格 |\n|------|------|\n| 语言标准 | C++20 |\n| 目标平台 | Linux (x86_64) |\n| 构建系统 | CMake 3.20+ |\n| 网络模型 | MainReactor + SubReactorPool (epoll LT) |\n| 依赖库 | ZLIB |\n| 协议 | Redis RESP 2.0 \u002F 3.0 |\n\n## 架构设计\n\n### 整体架构\n\n```\n                    redis-cli \u002F jedis \u002F redis-py\n                              │\n                              │ TCP (RESP)\n                              ▼\n                    ┌─────────────────────┐\n                    │    MainReactor      │\n                    │  (单线程 accept)    │\n                    └──────────┬──────────┘\n                               │ 轮询分发\n                    ┌──────────▼──────────┐\n                    │   SubReactorPool    │\n                    │ ┌────┐ ┌────┐       │\n                    │ │ SR │ │ SR │ ...   │\n                    │ │  0 │ │  1 │       │\n                    │ └────┘ └────┘       │\n                    └─────────────────────┘\n```\n\n### 核心模块\n\n| 层级 | 模块 | 职责 |\n|------|------|------|\n| 网络层 | MainReactor | 端口监听，accept 新连接 |\n| | SubReactorPool | 管理 SubReactor 线程，轮询负载均衡 |\n| | EventLoop | epoll 事件循环 |\n| | Connection | TCP 连接，缓冲区管理 |\n| 缓存层 | GlobalStorage | 64 分片哈希表，线程安全 |\n| | ExpireDict | 过期键管理 |\n| | ExpirationChecker | 后台过期键清理 |\n| 内存池 | ThreadCache | 线程本地缓存，无锁分配 |\n| | CentralCache | 中心缓存，细粒度锁 |\n| | PageCache | 页缓存，与系统交互 |\n| 命令层 | CommandFactory | 命令统一管理 |\n| 持久化层 | RDB | 快照持久化 |\n| | RDBScheduler | Fork\u002FCOW 快照调度 |\n\n## 支持的命令\n\n### STRING\n\n| 命令 | 说明 |\n|------|------|\n| GET key | 获取值 |\n| SET key value | 设置值 |\n| DEL key [key ...] | 删除键 |\n| EXISTS key [key ...] | 检查键是否存在 |\n| PING | 心跳检测 |\n| EXPIRE key seconds | 设置过期时间（秒） |\n| TTL key | 获取剩余生存时间（秒） |\n| PTTL key | 获取剩余生存时间（毫秒） |\n| PERSIST key | 移除过期时间 |\n| SETEX key seconds value | 设置值并指定过期时间 |\n\n### LIST\n\n| 命令 | 说明 |\n|------|------|\n| LPUSH key value [value ...] | 左侧推入 |\n| RPUSH key value [value ...] | 右侧推入 |\n| LPOP key | 左侧弹出 |\n| RPOP key | 右侧弹出 |\n| LLEN key | 获取长度 |\n| LRANGE key start stop | 范围查询（支持负索引） |\n\n### HASH\n\n| 命令 | 说明 |\n|------|------|\n| HSET key field value [field value ...] | 设置字段 |\n| HGET key field | 获取字段值 |\n| HDEL key field [field ...] | 删除字段 |\n| HLEN key | 获取字段数量 |\n| HGETALL key | 获取所有字段和值 |\n\n### SET\n\n| 命令 | 说明 |\n|------|------|\n| SADD key member [member ...] | 添加成员 |\n| SPOP key [count] | 随机弹出 |\n| SCARD key | 获取成员数量 |\n| SISMEMBER key member | 检查成员是否在集合中 |\n| SMEMBERS key | 获取所有成员 |\n\n### ZSET\n\n| 命令 | 说明 |\n|------|------|\n| ZADD key score member [score member ...] | 添加成员及分数 |\n| ZSCORE key member | 获取成员分数 |\n| ZCARD key | 获取成员数量 |\n| ZRANGE key start stop [WITHSCORES] | 按索引范围查询 |\n\n### RDB\n\n| 命令 | 说明 |\n|------|------|\n| SAVE | 同步保存快照 |\n| BGSAVE | 后台异步保存快照 |\n| LASTSAVE | 获取上次保存时间戳 |\n\n## 快速开始\n\n### 环境要求\n\n- Linux (x86_64)\n- GCC 12+ \u002F Clang 16+\n- CMake 3.20+\n- ZLIB\n\n### 编译\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fdingziming\u002FConcurrentCache.git\ncd ConcurrentCache\nmkdir build && cd build\ncmake .. -DCMAKE_BUILD_TYPE=Release\ncmake --build . --parallel\n```\n\n### 运行\n\n```bash\n.\u002Fconcurrentcache-server\n# 默认监听 0.0.0.0:6379\n```\n\n### 测试\n\n```bash\nredis-cli -p 6379\n\n127.0.0.1:6379> PING\nPONG\n\n127.0.0.1:6379> SET name concurrentcache\nOK\n\n127.0.0.1:6379> GET name\n\"concurrentcache\"\n\n127.0.0.1:6379> HSET user:1 name Alice age 25\n(integer) 2\n\n127.0.0.1:6379> HGETALL user:1\n1) \"name\"\n2) \"Alice\"\n3) \"age\"\n4) \"25\"\n\n127.0.0.1:6379> ZADD leaderboard 100 Alice 200 Bob 150 Charlie\n(integer) 3\n\n127.0.0.1:6379> ZRANGE leaderboard 0 -1 WITHSCORES\n1) \"Alice\"\n2) \"100\"\n3) \"Charlie\"\n4) \"150\"\n5) \"Bob\"\n6) \"200\"\n```\n\n## 性能表现\n\n本项目经过严格的压力测试，展现了卓越的高并发处理能力和极低的延迟。以下是性能表现：\n\n### 吞吐量与性能基准\n![Benchmark Dashboard](docs\u002Fbenchmark_dashboard.png)\n\n### 延迟分析\n![Latency Analysis](docs\u002Flatency_analysis.png)\n\n### 线性扩展性\n![Scalability](docs\u002Fscalability.png)\n\n## Docker\n\n### 使用预构建镜像\n\n```bash\ndocker pull ghcr.io\u002Fdingziming\u002Fconcurrentcache:latest\ndocker run -d -p 6379:6379 --name concurrentcache ghcr.io\u002Fdingziming\u002Fconcurrentcache:latest\nredis-cli -p 6379 PING\n```\n\n### 本地构建\n\n```bash\ndocker build -t concurrentcache:latest .\ndocker run -d -p 6379:6379 concurrentcache:latest\n```\n\n### Docker Compose\n\n```yaml\nversion: '3.8'\nservices:\n  concurrentcache:\n    image: ghcr.io\u002Fdingziming\u002Fconcurrentcache:latest\n    ports:\n      - \"6379:6379\"\n    volumes:\n      - .\u002Fdata:\u002Fapp\u002Fdata\n    restart: unless-stopped\n```\n\n```bash\ndocker-compose up -d\n```\n\n## 配置\n\n编辑 `conf\u002Fconcurrentcache.conf`：\n\n```ini\nport = 6379\nreactor_count = 32\nthread_pool_size = 32\nlog_level = 3\nrdb_path = .\u002Fdump.rdb\nrdb_save_interval = 3600\nrdb_dirty_threshold = 10000\nmax_entries = 2000000\ncluster_enabled = false\n```\n\n## 项目结构\n\n```\nsrc\u002F\n├── base\u002F                      # 基础组件\n│   ├── log.cpp\u002Fh             # 日志系统\n│   ├── config.cpp\u002Fh          # 配置管理\n│   ├── signal.cpp\u002Fh          # 信号处理\n│   ├── format.cpp\u002Fh          # 字符串格式化\n│   ├── lock.cpp\u002Fh            # 锁机制\n│   └── thread_pool.cpp\u002Fh     # 线程池\n│\n├── network\u002F                   # 网络层\n│   ├── socket.cpp\u002Fh          # Socket 封装\n│   ├── event_loop.cpp\u002Fh      # epoll 事件循环\n│   ├── channel.cpp\u002Fh         # 事件通道\n│   ├── connection.cpp\u002Fh       # 连接管理\n│   ├── buffer.cpp\u002Fh          # 缓冲区\n│   ├── main_reactor.cpp\u002Fh    # MainReactor\n│   ├── sub_reactor.cpp\u002Fh     # SubReactor\n│   └── sub_reactor_pool.cpp\u002Fh # SubReactor 池\n│\n├── memorypool\u002F                # 内存池\n│   ├── size_class.cpp\u002Fh      # Size Class 计算\n│   ├── thread_cache.cpp\u002Fh    # 线程本地缓存\n│   ├── central_cache.cpp\u002Fh   # 中心缓存\n│   ├── page_cache.cpp\u002Fh      # 页缓存\n│   ├── span.cpp\u002Fh            # Span 管理\n│   └── free_list.cpp\u002Fh       # 空闲链表\n│\n├── protocol\u002F                   # 协议层\n│   └── resp.cpp\u002Fh            # Redis RESP 协议\n│\n├── datatype\u002F                  # 数据类型\n│   └── object.cpp\u002Fh          # CacheObject\n│\n├── command\u002F                   # 命令层\n│   ├── command.h             # 命令基类\n│   ├── command_factory.cpp\u002Fh  # 命令工厂\n│   ├── string_cmd.h         # String 命令\n│   ├── list_cmd.h            # List 命令\n│   ├── hash_cmd.h            # Hash 命令\n│   ├── set_cmd.h             # Set 命令\n│   ├── zset_cmd.h            # ZSet 命令\n│   ├── cluster_cmd.cpp\u002Fh     # 集群命令\n│   ├── psync_cmd.cpp\u002Fh       # 主从同步\n│   └── restore_cmd.cpp\u002Fh     # 恢复命令\n│\n├── cache\u002F                     # 缓存核心\n│   ├── storage.cpp\u002Fh         # GlobalStorage\n│   ├── expire_dict.cpp\u002Fh      # 过期字典\n│   └── expiration_checker.cpp\u002Fh # 过期检查\n│\n├── persistence\u002F               # 持久化\n│   ├── rdb.cpp\u002Fh            # RDB 格式\n│   └── rdb_scheduler.cpp\u002Fh   # 快照调度\n│\n└── cluster\u002F                   # 集群\n    ├── cluster_common.h      # 公共定义\n    ├── cluster_node.cpp\u002Fh    # 节点结构\n    ├── cluster_state.cpp\u002Fh   # 集群状态\n    ├── cluster_server.cpp\u002Fh  # 集群服务\n    ├── cluster_link.cpp\u002Fh   # 节点链接\n    ├── cluster_connection.cpp\u002Fh # 连接管理\n    ├── cluster_gossip.cpp\u002Fh  # Gossip 协议\n    ├── replication_mgr.cpp\u002Fh # 主从复制\n    └── cluster_bus.cpp\u002Fh     # 集群总线\n```\n\n## 测试\n\n### 运行测试\n\n```bash\nctest --test-dir build --output-on-failure\n```\n\n### 单独测试\n\n| 测试 | 说明 |\n|------|------|\n| atomic-tests | 原子操作正确性 |\n| lock-correctness-tests | Mutex\u002FRWLock\u002FSpinLock 正确性 |\n| lock-deadlock-tests | 死锁检测 |\n| lock-race-tests | 数据竞争检测 |\n| sync-primitives-tests | CountDownLatch\u002FCyclicBarrier |\n| storage-test | GlobalStorage 增删改查 |\n| datatype-test | 五种数据类型 |\n| persistence-test | RDB 读写与恢复 |\n| cluster-test | 集群功能 |\n| stress-test | 高并发压力测试 |\n\n### Sanitizers\n\n```bash\n# AddressSanitizer\ncmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON\n\n# ThreadSanitizer\ncmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_TSAN=ON\n```\n\n## 版本历史\n\n| 版本 | 状态 | 说明 |\n|------|------|------|\n| V1.0 | 完成 | 单 Reactor 架构，基础命令 |\n| V2.0 | 完成 | MainSubReactor 分离，内存池，锁机制 |\n| V3.0 | 完成 | LIST\u002FHASH\u002FSET\u002FZSET 数据类型 |\n| V3.1 | 完成 | RDB 持久化 |\n| V4.0 | 完成 | 集群模式，Gossip 协议，主从复制 |\n\n## 编译选项\n\n```bash\n# Release 模式\ncmake .. -DCMAKE_BUILD_TYPE=Release\n\n# Debug 模式\ncmake .. -DCMAKE_BUILD_TYPE=Debug\n\n# Sanitizers\ncmake .. -DENABLE_ASAN=ON\ncmake .. -DENABLE_TSAN=ON\ncmake .. -DENABLE_UBSAN=ON\n```\n\n## 设计决策\n\n### 分段锁哈希表\n\nGlobalStorage 将哈希表分为 64 个分片，每个分片独立加锁。高并发场景下，操作分散到不同分片，显著降低锁竞争。\n\n### 三层内存池\n\n- ThreadCache：线程本地缓存，无锁分配，延迟最低\n- CentralCache：跨线程内存协调，细粒度锁\n- PageCache：直接与系统交互，大块内存分配\n\n### ARU 淘汰算法\n\n近似 LRU，通过 `last_access_time_ms` 实现。每 100ms 抽样检查过期键时，顺带淘汰最久未访问的键。\n\n## 参考资料\n\n- [Redis 设计与实现](https:\u002F\u002Fgithub.com\u002Fhuangz1990\u002Fredisbook)\n- [muduo 网络库](https:\u002F\u002Fgithub.com\u002Fchenshuo\u002Fmuduo)\n- [Linux 高性能服务器编程](https:\u002F\u002Fbook.douban.com\u002Fsubject\u002F24772279\u002F)\n- [RESP 协议规范](https:\u002F\u002Fredis.io\u002Ftopics\u002Fprotocol)\n\n## Star History\n\n[![Star History Chart](https:\u002F\u002Fapi.star-history.com\u002Fsvg?repos=dingziming\u002FConcurrentCache&type=Date)](https:\u002F\u002Fstar-history.com\u002F#dingziming\u002FConcurrentCache&Date)\n\n## 许可证\n\nMIT License - 详见 [LICENSE](LICENSE)\n","ConcurrentCache 是一个用 C++20 从零构建的高性能分布式内存对象缓存系统，兼容 Redis RESP 协议。项目核心功能包括多线程 Reactor 架构、64 分片分段锁哈希表以降低锁竞争、高效的三级内存管理架构（ThreadCache, CentralCache, PageCache），以及对五种数据类型（STRING, LIST, HASH, SET, ZSET）的支持。此外，它还具备持久化能力（RDB 快照）和集群支持（哈希槽分片、Gossip 协议、主从复制）。适用于需要高性能内存缓存且希望利用现有 Redis 客户端的应用场景，如实时数据分析、Web 应用加速等。",2,"2026-06-11 03:52:46","CREATED_QUERY"]