KeyDB as Redis Alternative Installation
KeyDB is a high-performance, multi-threaded fork of Redis that is fully API-compatible with Redis while delivering significantly higher throughput on multi-core systems. This guide covers installing KeyDB on Linux, configuring multi-threaded mode, using FLASH storage for large datasets, setting up active replication, and migrating from Redis.
Prerequisites
- Ubuntu 20.04/22.04 or CentOS 8/Rocky Linux 8+
- At least 2 GB RAM (more for production)
- Multi-core CPU (KeyDB's benefit is most visible on 4+ cores)
- Root or sudo access
- For FLASH: NVMe SSD recommended
Install KeyDB on Linux
Ubuntu/Debian (official repository):
# Add KeyDB repository
curl -fsSL https://download.keydb.dev/pkg/open_source/gpg | sudo gpg --dearmor -o /usr/share/keyrings/keydb.gpg
echo "deb [signed-by=/usr/share/keyrings/keydb.gpg] https://download.keydb.dev/pkg/open_source/deb $(lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/keydb.list
sudo apt update
sudo apt install -y keydb
# Enable and start
sudo systemctl enable keydb-server
sudo systemctl start keydb-server
# Verify installation
keydb-cli ping
# PONG
keydb-cli info server | grep -E "keydb_version|redis_version"
CentOS/Rocky Linux:
# Add KeyDB repository
sudo rpm --import https://download.keydb.dev/pkg/open_source/gpg
cat > /etc/yum.repos.d/keydb.repo << 'EOF'
[keydb]
name=KeyDB
baseurl=https://download.keydb.dev/pkg/open_source/rpm/el$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=https://download.keydb.dev/pkg/open_source/gpg
EOF
sudo dnf install -y keydb
sudo systemctl enable --now keydb-server
Install from binary (latest version):
# Download the latest KeyDB binary
wget https://github.com/Snapchat/KeyDB/releases/latest/download/keydb-latest-linux-x86_64.tar.gz
tar -xzf keydb-latest-linux-x86_64.tar.gz
sudo cp keydb/keydb-server keydb/keydb-cli /usr/local/bin/
Basic Configuration
KeyDB uses the same configuration format as Redis:
# Main config file location
sudo nano /etc/keydb/keydb.conf
Key settings:
# /etc/keydb/keydb.conf
# Bind address
bind 127.0.0.1
port 6379
# Require password
requirepass your-strong-password-here
# Max memory
maxmemory 1gb
maxmemory-policy allkeys-lru
# Persistence
save 900 1
save 300 10
save 60 10000
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
# Log level
loglevel notice
logfile /var/log/keydb/keydb-server.log
# Data directory
dir /var/lib/keydb
sudo systemctl restart keydb-server
# Test with password
keydb-cli -a your-strong-password-here ping
Multi-Threaded Performance
KeyDB's core advantage is native multi-threading, unlike Redis which is single-threaded:
# /etc/keydb/keydb.conf
# Enable server threads (set to number of CPU cores)
# Use 'nproc' to find your CPU count
server-threads 4
# Thread multiplexing (allows threads to share connections)
server-thread-affinity true
# Background threads for I/O operations
io-threads 4
io-threads-do-reads yes
# Check CPU cores
nproc
# Benchmark comparison: KeyDB vs Redis
# Run with KeyDB
keydb-benchmark -a your-password -c 50 -n 100000 -q
# For comparison (if Redis is on a different port):
# redis-benchmark -p 6380 -c 50 -n 100000 -q
# Check server thread stats
keydb-cli -a your-password info keydb | grep -i thread
Benchmarks typically show KeyDB achieving 2-3x higher throughput than Redis on 4+ core systems for write-heavy workloads.
Active Replication Setup
KeyDB's active replication allows all nodes to accept both reads and writes, unlike Redis's active-passive setup:
# Node 1 configuration (/etc/keydb/keydb.conf on server1)
bind 0.0.0.0
port 6379
requirepass replicationpassword
masterauth replicationpassword
# Point to peer node (active replication)
replicaof 192.168.1.2 6379
# Allow writes on all nodes (active replication mode)
active-replica yes
multi-master yes
# Node 2 configuration (/etc/keydb/keydb.conf on server2)
bind 0.0.0.0
port 6379
requirepass replicationpassword
masterauth replicationpassword
replicaof 192.168.1.1 6379
active-replica yes
multi-master yes
# Restart both nodes
sudo systemctl restart keydb-server
# Verify active replication on Node 1
keydb-cli -a replicationpassword info replication
# Write on Node 1
keydb-cli -a replicationpassword set testkey "from-node1"
# Read from Node 2 - should return "from-node1"
keydb-cli -h 192.168.1.2 -a replicationpassword get testkey
FLASH Storage Configuration
KeyDB FLASH stores less-frequently accessed data on NVMe SSD, allowing much larger datasets:
# Install KeyDB with FLASH support
# Flash support may require the enterprise edition or specific build
# Check: keydb-server --version | grep flash
# Configure FLASH in keydb.conf
# /etc/keydb/keydb.conf
# Enable FLASH storage
# Requires KeyDB Pro or a FLASH-enabled build
storage-provider flash /mnt/keydb-flash
# Max memory in RAM (hot data)
maxmemory 2gb
maxmemory-policy allkeys-lru
# FLASH stores the rest (configure mount point on fast SSD)
# Prepare NVMe mount for FLASH
sudo mkfs.ext4 /dev/nvme0n1p1
sudo mkdir -p /mnt/keydb-flash
sudo mount /dev/nvme0n1p1 /mnt/keydb-flash
sudo chown keydb:keydb /mnt/keydb-flash
# Add to /etc/fstab for persistence
echo "/dev/nvme0n1p1 /mnt/keydb-flash ext4 defaults,noatime 0 2" | sudo tee -a /etc/fstab
sudo systemctl restart keydb-server
Redis Compatibility
KeyDB is a drop-in replacement for Redis with full API compatibility:
# Any Redis client works with KeyDB
# Python example
pip install redis
python3 << 'EOF'
import redis
# Connect to KeyDB exactly as you would to Redis
r = redis.Redis(host='localhost', port=6379, password='your-password', decode_responses=True)
r.set('key', 'value')
print(r.get('key')) # value
r.lpush('mylist', 'a', 'b', 'c')
print(r.lrange('mylist', 0, -1)) # ['c', 'b', 'a']
r.hset('myhash', 'field1', 'value1')
print(r.hgetall('myhash')) # {'field1': 'value1'}
EOF
# Node.js with ioredis
npm install ioredis
node -e "
const Redis = require('ioredis');
const client = new Redis({ host: 'localhost', port: 6379, password: 'your-password' });
client.set('foo', 'bar').then(() => client.get('foo')).then(v => { console.log(v); client.quit(); });
"
KeyDB supports all Redis commands including:
- All data structures: String, List, Hash, Set, Sorted Set, Stream
- Lua scripting and EVAL
- Pub/Sub
- Transactions (MULTI/EXEC)
- Redis Sentinel (for failover monitoring)
Migrate from Redis
# Method 1: Redis DUMP/RESTORE - for individual keys
# Method 2: RDB file migration (fastest for full datasets)
# Step 1: Create an RDB snapshot on the Redis server
redis-cli -p 6380 BGSAVE
# Wait for save to complete
redis-cli -p 6380 LASTSAVE
# Step 2: Copy the RDB file to KeyDB server
scp /var/lib/redis/dump.rdb user@keydb-server:/var/lib/keydb/dump.rdb
sudo chown keydb:keydb /var/lib/keydb/dump.rdb
# Step 3: Stop KeyDB, replace data, restart
sudo systemctl stop keydb-server
sudo cp /var/lib/keydb/dump.rdb /var/lib/keydb/dump.rdb.bak
sudo systemctl start keydb-server
# Verify data is loaded
keydb-cli -a your-password dbsize
# Should match original Redis dbsize
# Method 3: Live replication migration
# Configure KeyDB to replicate from existing Redis temporarily
# In keydb.conf:
# replicaof <redis-host> 6379
# Let it sync, then remove the replicaof directive
# keydb-cli replicaof NO ONE
Troubleshooting
KeyDB won't start - address already in use:
# Check if Redis is running on the same port
ss -tlnp | grep 6379
sudo systemctl stop redis-server
# Or change KeyDB port
# In keydb.conf: port 6380
Memory limits exceeded immediately:
# Check actual memory usage
keydb-cli -a password info memory | grep -E "used_memory_human|maxmemory"
# Reduce maxmemory or increase system RAM
# Set proper eviction policy
keydb-cli -a password config set maxmemory-policy allkeys-lru
Active replication sync issues:
# Check replication status on both nodes
keydb-cli -a password info replication
# Force a full resync
keydb-cli -a password replicaof NO ONE
keydb-cli -a password replicaof 192.168.1.2 6379
Performance not better than Redis:
# Verify multi-threading is active
keydb-cli -a password info keydb | grep server_thread
# Check if server-threads is > 1 in config
keydb-cli -a password config get server-threads
# Run benchmark to confirm
keydb-benchmark -a password -c 100 -n 1000000 --threads 4 -q
Conclusion
KeyDB delivers Redis-compatible caching and data storage with significantly better multi-threaded performance, making it a strong choice for high-throughput workloads on multi-core VPS or baremetal servers. Active replication eliminates single points of failure without a separate Redis Sentinel setup, and FLASH storage enables cost-effective large datasets. Migrating from Redis requires only copying the RDB file and updating connection strings.


