Skip to main content

Redis on a VPS: Installation and Cache Configuration

VDS / VPS · 01.11.2025 · 5 min read
Illustration for “Redis on a VPS: Installation and Cache Configuration”

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:

  1. Plugins → Add New → “Redis Object Cache”
  2. Add to wp-config.php: define('WP_REDIS_HOST', '127.0.0.1'); define('WP_REDIS_PASSWORD', 'YourPassword');
  3. 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
💡 For WordPress with Redis Object Cache, TTFB drops from 300–500ms to 50–80ms. The difference is noticeable on high-traffic sites.

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

PolicyBehaviorUse case
allkeys-lruEvict least recently usedCache
volatile-lruEvict only keys with TTLSessions + cache
noevictionError on overflowQueues
⚠️ Never expose Redis on a public interface without a VPN or firewall. Redis has no TLS encryption by default.

Common Redis Errors

MessageWhat it means
NOAUTH Authentication requiredrequirepass is set in redis.conf, but the client connects without a password or an AUTH command
MISCONF Redis is configured to save RDB snapshotsThe 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 > maxmemoryThe maxmemory limit was reached, and the noeviction policy won't free space automatically
Could not connect to Redis: Connection refusedThe 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

CriterionRedisMemcached
Data structuresStrings, lists, hashes, setsStrings only
Persistence to diskYes (RDB/AOF)No, memory only
MultithreadingMostly single-threadedMultithreaded out of the box
Typical use caseCache, queues, sessionsSimple 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.

Was this article helpful?
← Back to Knowledge Base Ask Support