Redis is an in-memory key-value store, widely used for caching, web sessions, queues (with appropriate libraries), and rate limiting. This guide installs Redis on Ubuntu/Debian with a local-only default (recommended).
Prerequisites
- VPS with
sudo - Ubuntu 20.04+ or Debian 11+
Installation
Bash1sudo apt update && sudo apt upgrade -y 2sudo apt install -y redis-server 3sudo systemctl enable redis-server 4sudo systemctl start redis-server 5sudo systemctl status redis-server
Quick test
Bashredis-cli ping
Expected: PONG.
Bashredis-cli SET test "hello" redis-cli GET test
Main configuration file
On Debian/Ubuntu, configuration is often /etc/redis/redis.conf.
Important settings:
bind: often127.0.0.1 ::1— keep localhost only if the app runs on the same server.protected-mode yes: keep enabled unless you have proper authentication and exposure rules.supervised systemd: good integration with systemd (depending on package version).
After edits:
Bashsudo systemctl restart redis-server
Password (recommended if widening network access)
In redis.conf:
Configrequirepass your_long_password
Connect:
Bashredis-cli -a 'your_long_password' ping
Never commit passwords to Git; use environment variables.
Memory and persistence
- maxmemory: cap RAM on small VPS (e.g.
maxmemory 256mbwithmaxmemory-policy allkeys-lrufor cache-only use). - RDB/AOF: Redis can persist to disk; pure volatile cache setups may reduce persistence (understand data-loss risk).
Security
- Do not expose Redis to the internet without tunnel, VPN, or very strict firewall rules.
- Combine with UFW for other public ports.
Application connection string
Local typical URL:
TEXTredis://127.0.0.1:6379
With password:
TEXTredis://:[email protected]:6379
Troubleshooting
- Connection refused: service stopped or wrong port; check
sudo systemctl status redis-serverandss -tlnp | grep 6379. - OOM: lower
maxmemoryor add RAM.