# DragonflyDB — Modern In-Memory Datastore Replacing Redis > DragonflyDB is a modern replacement for Redis and Memcached. Written in C++ with a multi-threaded, shared-nothing architecture that achieves 25x throughput improvement over Redis. Fully compatible with Redis and Memcached APIs. ## Install Save in your project root: ## Quick Use ```bash # Docker docker run -d --name dragonfly -p 6379:6379 docker.dragonflydb.io/dragonflydb/dragonfly # Connect via redis-cli (fully compatible) redis-cli -p 6379 > SET hello world > GET hello > HSET user:1 name William email w@tokrepo.com > HGETALL user:1 > LPUSH queue task1 task2 > RPOP queue ``` ## Intro DragonflyDB is a modern in-memory datastore designed as a drop-in replacement for Redis and Memcached. Built from scratch in C++ with a multi-threaded, shared-nothing architecture that uses all CPU cores efficiently. In benchmarks, Dragonfly achieves 25x the throughput of Redis on a single node while reducing memory usage by up to 40%. - **Repo**: https://github.com/dragonflydb/dragonfly - **Stars**: 30K+ - **Language**: C++ - **License**: BSL 1.1 (converts to Apache 2.0 after 4 years) ## What DragonflyDB Does - **Redis compatible** — RESP protocol, most Redis commands - **Memcached compatible** — text and binary protocols - **Multi-threaded** — shared-nothing, scales across all cores - **Memory efficient** — novel data structures use ~40% less RAM - **Snapshots** — RDB-compatible persistence - **Replication** — Redis-compatible replication protocol - **Pub/Sub** — full pub/sub support - **Lua scripting** — Redis Lua scripts work unchanged - **Cluster mode** — emulated cluster for Redis cluster clients - **ACL** — Redis-compatible ACL system ## Architecture Shared-nothing multi-threaded design: each thread owns a slice of the keyspace. No global locks. Novel dashtable data structure replaces Redis dict for lower memory overhead and better cache locality. IO is handled via io_uring (Linux) for minimal syscall overhead. ## Self-Hosting ```yaml version: "3" services: dragonfly: image: docker.dragonflydb.io/dragonflydb/dragonfly ports: ["6379:6379"] volumes: - dragonfly-data:/data ulimits: memlock: -1 volumes: dragonfly-data: ``` ## Key Features - Redis + Memcached wire compatibility - 25x throughput vs Redis (single instance) - 40% less memory usage - Multi-threaded (shared-nothing) - RDB snapshot persistence - Replication - Lua scripting - ACL security - io_uring (Linux) - Drop-in replacement ## Comparison | Store | Threads | Protocol | Memory | |---|---|---|---| | DragonflyDB | Multi (shared-nothing) | Redis + Memcached | Best | | Redis | Single | RESP | Good | | Valkey | Single | RESP | Good (Redis fork) | | KeyDB | Multi (shared) | RESP | Good | | Garnet (MS) | Multi | RESP | Good | ## 常见问题 FAQ **Q: 能直接替换 Redis 吗?** A: 大部分场景可以。RESP 协议兼容,大部分 Redis 命令支持。少数高级 Redis 功能(Redis Modules、某些 cluster 边缘行为)不支持。 **Q: BSL 限制?** A: 4 年后自动转 Apache 2.0。期间自用完全 OK,只是不能做托管 Dragonfly 服务与官方竞争。 **Q: 为什么这么快?** A: 多线程 + 无锁 shared-nothing + io_uring + 紧凑数据结构(dashtable)。单机可以跑满一台 96 核服务器。 ## 来源与致谢 Sources - Docs: https://www.dragonflydb.io/docs - GitHub: https://github.com/dragonflydb/dragonfly - License: BSL 1.1 --- Source: https://tokrepo.com/en/workflows/290af6cf-3641-11f1-9bc6-00163e2b0d79 Author: AI Open Source