Storage Backends
MilliCache works with any Redis-compatible server. This guide covers supported backends, configuration, and recommendations.
Supported Backends#Copied!
| Backend | License | Key Feature | Best For |
|---|---|---|---|
| Redis | RSALv2 | Most popular, proven | Most deployments |
| ValKey | BSD-3 | Open-source Redis fork | License-concerned users |
| KeyDB | BSD-3 | Multithreaded | High-throughput needs |
| Dragonfly | BSL | Memory efficient | Large cache requirements |
All backends use the same protocol and configuration. Your choice depends on licensing preferences, performance needs, and hosting availability.
Quick Comparison#Copied!
Redis#Copied!
The original in-memory data store. Most documentation, hosting support, and community resources.
- Pros: Battle-tested, extensive documentation, widest hosting support
- Cons: RSALv2 license may concern some users
- Install: redis.io/docs/install
ValKey#Copied!
Linux Foundation fork of Redis, fully open-source under BSD-3 license.
- Pros: Fully open-source, active development, drop-in Redis replacement
- Cons: Newer project, less hosting support currently
- Install: valkey.io/docs
KeyDB#Copied!
Multithreaded Redis fork with improved performance on multi-core systems.
- Pros: Higher throughput, MVCC for better concurrency
- Cons: Less widespread than Redis
- Install: docs.keydb.dev
Dragonfly#Copied!
Modern Redis alternative with significantly better memory efficiency.
- Pros: Uses less memory for same data, faster on large datasets
- Cons: Newer, Business Source License
- Install: dragonflydb.io/docs
MilliCache Configuration#Copied!
Connection settings are the same for all backends.
Basic Connection#Copied!
1// wp-config.php
2define( 'WP_CACHE', true );
3
4define( 'MC_STORAGE_HOST', '127.0.0.1' );
5define( 'MC_STORAGE_PORT', 6379 );
With Authentication#Copied!
1define( 'MC_STORAGE_HOST', 'redis.example.com' );
2define( 'MC_STORAGE_PORT', 6379 );
3define( 'MC_STORAGE_USERNAME', 'your-username' );
4define( 'MC_STORAGE_PASSWORD', 'your-password' );
Using Unix Socket#Copied!
1define( 'MC_STORAGE_HOST', '/var/run/redis/redis.sock' );
2define( 'MC_STORAGE_PORT', 0 ); // Ignored for sockets
With TLS (e.g. AWS ElastiCache)#Copied!
1define( 'MC_STORAGE_HOST', 'tls://master.example.cache.amazonaws.com' );
2define( 'MC_STORAGE_PORT', 6379 );
Multiple Sites on Same Server#Copied!
Use different databases or prefixes:
1// Site A
2define( 'MC_STORAGE_DB', 0 );
3define( 'MC_STORAGE_PREFIX', 'sitea' );
4
5// Site B
6define( 'MC_STORAGE_DB', 1 );
7define( 'MC_STORAGE_PREFIX', 'siteb' );
All Connection Constants#Copied!
| Constant | Default | Description |
|---|---|---|
MC_STORAGE_HOST |
127.0.0.1 |
Hostname, IP, socket, tls://host, or a node array (see below) |
MC_STORAGE_PORT |
6379 |
TCP port (0 for sockets) |
MC_STORAGE_USERNAME |
'' |
ACL username (default user if empty) |
MC_STORAGE_PASSWORD |
'' |
AUTH password |
MC_STORAGE_DB |
0 |
Database number (0-15) |
MC_STORAGE_PERSISTENT |
true |
Use persistent connections |
MC_STORAGE_PREFIX |
mll |
Key prefix |
MC_STORAGE_TIMEOUT |
1.0 |
Connection timeout in seconds |
MC_STORAGE_READ_TIMEOUT |
2.0 |
Read/write timeout in seconds |
Timeouts#Copied!
MC_STORAGE_TIMEOUT (default 1.0) bounds connecting to the server, so an
unreachable backend falls back to uncached WordPress quickly instead of stalling
the request. MC_STORAGE_READ_TIMEOUT (default 2.0) bounds waiting for a
command response; raise it only if you serve very large cached responses over a
slow link.
High Availability: Replication & Sentinel#Copied!
For read-scaling, a node-local replica, or automatic failover, set
MC_STORAGE_HOST to an array. A master key selects replication; a service
key selects Sentinel. These modes are configured in wp-config.php only; the
Settings screen shows a read-only notice when an array is active.
MC_STORAGE_USERNAME, MC_STORAGE_PASSWORD, and MC_STORAGE_DB apply to every
node. Each address is host, host:port, or tls://host[:port].
Replication (master + replicas)#Copied!
1define( 'MC_STORAGE_HOST', array(
2 'master' => 'master.example.com', // writes
3 'replicas' => array( '127.0.0.1', 'replica.tld:6380' ), // reads
4) );
5
6define( 'MC_STORAGE_PASSWORD', 'shared-secret' ); // applied to all nodes
replicas is optional and accepts a single address or a list. Replication is
asynchronous, so a just-written entry may briefly lag on a replica.
Sentinel (managed failover)#Copied!
1define( 'MC_STORAGE_HOST', array(
2 'service' => 'mymaster',
3 'sentinels' => array( '10.0.0.1:26379', '10.0.0.2:26379' ),
4) );
Sentinel discovers the master and re-resolves it on failover. Cluster mode (sharding across multiple masters) is not supported.
A misconfigured array (both master and service, Sentinel without
sentinels, or no recognized key) disables the cache and logs the reason rather
than connecting to the wrong server.
Recommended Server Configuration#Copied!
These settings are recommended for WordPress caching workloads:
1# Memory allocation (adjust based on your needs)
2maxmemory 256mb
3maxmemory-policy allkeys-lru
4
5# Persistence (optional - cache can be regenerated)
6save ""
7appendonly no
8
9# Performance
10tcp-keepalive 300
11timeout 0
12
13# Security (if exposed to network)
14bind 127.0.0.1
15requirepass your-strong-password
Memory Sizing#Copied!
| Site Size | Recommended Memory |
|---|---|
| Small (< 100 pages) | 64 MB |
| Medium (100-1000 pages) | 128-256 MB |
| Large (1000+ pages) | 512 MB+ |
The allkeys-lru eviction policy automatically removes least-recently-used entries when memory is full.
Applying Settings at Runtime#Copied!
You don't have to edit the Redis configuration file to change these. The memory
limit and eviction policy can both be applied live with CONFIG SET, with no
restart:
1redis-cli CONFIG SET maxmemory 512mb
2redis-cli CONFIG SET maxmemory-policy allkeys-lru
To target the exact server MilliCache is configured to use (host, port,
database, and password) without looking those details up, open a session with
wp millicache cli and run the commands there:
1wp millicache cli
2127.0.0.1:6379> CONFIG SET maxmemory 512mb
3127.0.0.1:6379> CONFIG SET maxmemory-policy allkeys-lru
4127.0.0.1:6379> quit
CONFIG SET takes effect immediately but is lost on the next Redis restart. To
make the change permanent, either add the same directives to your Redis
configuration file, or run CONFIG REWRITE to write the running configuration
back to that file (this requires Redis to already be started from a config
file):
1redis-cli CONFIG REWRITE
Testing Your Connection#Copied!
After configuration, verify the connection:
1# Quick test
2wp millicache test
3
4# Check status
5wp millicache status
6
7# View stats
8wp millicache stats
Troubleshooting Connection Issues#Copied!
Connection Refused#Copied!
Error: Connection refused
Causes:
- Server not running
- Wrong host/port
- Firewall blocking connection
Solutions:
1# Check if Redis is running
2redis-cli ping
3
4# Check listening port
5netstat -tlnp | grep 6379
6
7# Test connection manually
8redis-cli -h 127.0.0.1 -p 6379 ping
Authentication Failed#Copied!
Error: NOAUTH Authentication required
Solution: Set the authentication constants:
1define( 'MC_STORAGE_USERNAME', 'your-username' ); // omit if using default user
2define( 'MC_STORAGE_PASSWORD', 'your-password' );
Timeout#Copied!
Error: Connection timed out
Causes:
- Server overloaded
- Network issues
- Firewall timeout
Solutions:
- Check server resources
- Verify network connectivity
- Check firewall rules
- If the backend is healthy but distant, raise
MC_STORAGE_TIMEOUT(connection) orMC_STORAGE_READ_TIMEOUT(command response) above their1.0/2.0second defaults
Cloud Provider Options#Copied!
Most cloud providers offer managed Redis:
| Provider | Service |
|---|---|
| AWS | ElastiCache for Redis |
| Google Cloud | Memorystore |
| Azure | Azure Cache for Redis |
| DigitalOcean | Managed Redis |
| Upstash | Serverless Redis |
For managed services, use the provided connection details in your MilliCache configuration.
Performance Tips#Copied!
- Run locally when possible: Same-machine Redis has lowest latency
- Use persistent connections: Reduces connection overhead
- Enable compression:
MC_CACHE_GZIPreduces network transfer - Size memory appropriately: Avoid frequent evictions
- Monitor with
wp millicache stats: Track cache efficiency
Next Steps#Copied!
- Configuration Reference: All settings
- WP-CLI Commands: Command reference
- Troubleshooting: Common issues