# 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 the content below to `.claude/skills/` or append to your `CLAUDE.md`: ## 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: Can it directly replace Redis?** A: Yes in most scenarios. The RESP protocol is compatible, and most Redis commands are supported. A few advanced Redis features (Redis Modules, some cluster edge behaviors) are not. **Q: BSL restrictions?** A: Automatically converts to Apache 2.0 after 4 years. In the meantime, self-use is completely fine; you just can't run a managed Dragonfly service competing with the official one. **Q: Why is it so fast?** A: Multithreading + lock-free shared-nothing + io_uring + compact data structures (dashtable). A single machine can saturate a 96-core server. ## Sources - Docs: https://www.dragonflydb.io/docs - GitHub: https://github.com/dragonflydb/dragonfly - License: BSL 1.1 --- Source: https://tokrepo.com/en/workflows/dragonflydb-modern-memory-datastore-replacing-redis-290af6cf Author: AI Open Source