Redis is an in-memory data store. Instead of querying the database on every page view, the data is served from lightning-fast RAM.
Installing Redis
sudo apt update
sudo apt install -y redis-server
sudo systemctl enable redis
sudo systemctl start redis
# Check that it works
redis-cli ping
# Response: PONG
Configuring Redis
sudo nano /etc/redis/redis.conf
# Limit memory (for example, 256 MB):
maxmemory 256mb
maxmemory-policy allkeys-lru
# Set a password:
requirepass YourStrongPassword
# Listen on localhost only (safe):
bind 127.0.0.1 ::1
sudo systemctl restart redis
Redis + WordPress
Install the Redis Object Cache plugin:
- Plugins → Add New → “Redis Object Cache”
- Add to
wp-config.php:define('WP_REDIS_HOST', '127.0.0.1');define('WP_REDIS_PASSWORD', 'YourPassword'); - Activate it in the plugin settings
Redis + Laravel
# .env:
CACHE_DRIVER=redis
SESSION_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=YourPassword
REDIS_PORT=6379
Monitoring Redis
redis-cli -a YourPassword info memory
redis-cli -a YourPassword monitor # All commands in real time
redis-cli -a YourPassword info stats
Main redis.conf settings
# /etc/redis/redis.conf
# Bind to localhost only (security!)
bind 127.0.0.1
# Password
requirepass YourStrongPassword123
# Maximum memory
maxmemory 256mb
maxmemory-policy allkeys-lru
# Persistent storage (RDB — periodic snapshot)
save 900 1
save 300 10
# AOF (every second — balance of reliability and speed)
appendonly yes
appendfsync everysec
Memory eviction policies
| Policy | Behavior | Use case |
|---|---|---|
| allkeys-lru | Evict least recently used | Cache |
| volatile-lru | Evict only keys with TTL | Sessions + cache |
| noeviction | Error on overflow | Queues |
Common Redis Errors
| Message | What it means |
|---|---|
| NOAUTH Authentication required | requirepass is set in redis.conf, but the client connects without a password or an AUTH command |
| MISCONF Redis is configured to save RDB snapshots | The disk is full or there's no permission to write the RDB file — Redis blocks writes until the problem is fixed |
| OOM command not allowed when used memory > maxmemory | The maxmemory limit was reached, and the noeviction policy won't free space automatically |
| Could not connect to Redis: Connection refused | The service isn't running, or bind is restricted to an address other than the one the client is using |
Redis vs Memcached: Which to Choose
| Criterion | Redis | Memcached |
|---|---|---|
| Data structures | Strings, lists, hashes, sets | Strings only |
| Persistence to disk | Yes (RDB/AOF) | No, memory only |
| Multithreading | Mostly single-threaded | Multithreaded out of the box |
| Typical use case | Cache, queues, sessions | Simple object cache |
When Redis Isn't a Fit
- The dataset is clearly larger than the server's available RAM, and there's no budget for a memory upgrade
- You only need a primitive key-value cache with no persistence — Memcached is simpler here and needs less memory for internal structures
- The application needs a full relational model with transactions and joins — that's a job for PostgreSQL or MySQL, not Redis
- The team isn't ready to run and monitor another service's memory separately from the main application
Verifying the Result
# How many keys are already in the database
redis-cli -a YourPassword dbsize
# Current memory limit
redis-cli -a YourPassword config get maxmemory
# Memory actually in use
redis-cli -a YourPassword info memory | grep used_memory_human
If dbsize is growing but the application hasn't sped up, check that it's actually reading from Redis rather than just writing to it. See the table above for eviction policies, and services on a VDS for broader server setup.
Estimating the Memory You Need
Before setting maxmemory, it helps to know the rough scale for your project. A single WordPress session with Redis Object Cache typically uses anywhere from a few kilobytes to a couple hundred kilobytes, depending on the number of queries and plugins. For a site with moderate traffic, 128-256 MB of memory for Redis is usually enough; online stores with a large catalog and active session caching can run into a gigabyte or more — check this with info memory rather than guessing.
Redis for Queues: a Separate Database or a Separate Instance
If Redis is already serving as the site's cache and the application also needs a task queue (for example, Laravel Queue), don't mix them into one logical Redis database without separation. The simplest approach is to use different database numbers (SELECT 0-15 by default) for the cache and the queue — that's not full resource isolation, but it lets you clear the cache with FLUSHDB without touching the job queue in another database on the same instance.