Redis is a fast, in-memory data store used as a cache, session store, message broker, and queue backend. It dramatically reduces database load and speeds up applications like WordPress, Laravel, and Node.js APIs.
Prerequisites
- Ubuntu 22.04/24.04 or Debian 11/12 VPS
- Root or sudo access
Step 1 — Install Redis
sudo apt update
sudo apt install redis-server -y
Step 2 — Enable and Start Redis
sudo systemctl enable redis-server
sudo systemctl start redis-server
sudo systemctl status redis-server
Step 3 — Test the Connection
redis-cli ping
Expected response: PONG
Step 4 — Secure Redis
sudo nano /etc/redis/redis.conf
Set a strong password:
requirepass CHANGE_ME_STRONG_PASSWORD
Confirm Redis only binds to localhost (default) unless remote access is genuinely required:
bind 127.0.0.1 -::1
Disable dangerous commands in production if not needed:
rename-command FLUSHALL ""
rename-command FLUSHDB ""
Step 5 — Restart Redis
sudo systemctl restart redis-server
Step 6 — Test Authentication
redis-cli
AUTH CHANGE_ME_STRONG_PASSWORD
PING
Basic Redis Commands
SET key value
GET key
DEL key
EXPIRE key 60
TTL key
KEYS *
FLUSHALL
Setting a Memory Limit and Eviction Policy
maxmemory 256mb
maxmemory-policy allkeys-lru
allkeys-lru automatically evicts the least recently used keys once the memory limit is reached — appropriate for cache-only use cases.
Enabling Persistence (If Needed)
By default Redis periodically snapshots to disk (RDB). For applications needing minimal data loss, enable append-only file persistence:
appendonly yes
Common Errors
"NOAUTH Authentication required" — a password is set; authenticate with AUTH your_password before other commands.
Redis won't start:
sudo journalctl -u redis-server
Best Practices
- Always set a password with
requirepass, even for local-only access - Keep
bind 127.0.0.1unless remote access is explicitly required and firewall-restricted - Set
maxmemoryto prevent Redis from consuming all available RAM
FAQ
Does Redis replace my primary database?
No — Redis is typically used alongside a relational or document database to cache frequently accessed data and reduce load on the primary store.
Related Articles
- How to Run MySQL, PostgreSQL & Redis in Docker Containers
- How to Install and Secure MySQL 8 on Ubuntu & Debian
- How to Check VPS Resource Usage (CPU, RAM & Disk)
