DEV Community

Alex Spinov
Alex Spinov

Posted on

KeyDB Has a Free API: Multithreaded Redis Fork with Active Replication

KeyDB is a high-performance fork of Redis that uses multithreading to deliver 5x the throughput on the same hardware. It is fully compatible with the Redis API and adds features like active-active replication and FLASH storage.

What Is KeyDB?

KeyDB takes Redis and adds multithreading, active-active replication, and FLASH storage support. It maintains full compatibility with Redis clients and commands while dramatically improving performance.

Key Features:

  • Redis API compatible
  • Multithreaded (uses all CPU cores)
  • Active-active geo-replication
  • FLASH storage support (SSD as RAM extension)
  • Subkey expires
  • Non-blocking KEYS command
  • ModJS (JavaScript scripting)
  • Up to 5x throughput vs Redis

Quick Start

# Docker
docker run -d --name keydb -p 6379:6379 \
  eqalpha/keydb --server-threads 4

# Connect with any Redis client!
redis-cli -p 6379
Enter fullscreen mode Exit fullscreen mode

KeyDB API (Redis-Compatible)

import redis

# Same Redis client works!
r = redis.Redis(host="localhost", port=6379)

# Basic operations
r.set("user:1:name", "Alice")
r.set("user:1:email", "alice@example.com")
print(r.get("user:1:name").decode())  # Alice

# Hash
r.hset("product:101", mapping={
    "name": "Widget Pro",
    "price": "29.99",
    "stock": "150"
})
product = r.hgetall("product:101")
print({k.decode(): v.decode() for k, v in product.items()})

# Sorted set (leaderboard)
r.zadd("leaderboard", {"alice": 1500, "bob": 2300, "charlie": 1800})
top = r.zrevrange("leaderboard", 0, 2, withscores=True)
for name, score in top:
    print(f"{name.decode()}: {int(score)} points")

# Pub/Sub
pubsub = r.pubsub()
pubsub.subscribe("notifications")
r.publish("notifications", "New order received!")

# Streams
r.xadd("events", {"type": "purchase", "amount": "99.99", "user": "alice"})
events = r.xrange("events", "-", "+", count=10)
for event_id, data in events:
    print(f"{event_id.decode()}: {data}")
Enter fullscreen mode Exit fullscreen mode

KeyDB-Specific Features

# Active-active replication
keydb-server --active-replica yes --replicaof other-node 6379

# FLASH storage (use SSD as RAM extension)
keydb-server --storage-provider flash /data/flash --maxmemory 1gb
# Now KeyDB uses 1GB RAM + SSD for overflow

# Subkey expires (expire individual hash fields!)
keydb-cli EXPIREMEMBER myhash myfield 60
# This hash field expires in 60 seconds

# Server threads
keydb-server --server-threads 8  # Use 8 threads
Enter fullscreen mode Exit fullscreen mode

KeyDB vs Redis

Feature KeyDB Redis
Threading Multi-threaded Single-threaded
Active-active Built-in Redis Enterprise
FLASH storage Built-in Redis Enterprise
Subkey expires Yes No
Throughput Up to 5x Baseline
API Redis compatible Redis
License BSD SSPL (7.0+)

Resources


Need to scrape web data for your caching layer? Check out my web scraping tools on Apify — production-ready actors for Reddit, Google Maps, and more. Questions? Email me at spinov001@gmail.com

Top comments (0)