Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Know it before you install
Redis is a key → value store in RAM. When memory is full, it removes keys by a rule (eviction) or refuses writes. It can save the data to disk (RDB snapshots and/or the AOF log) so it survives a restart.
| Item | RHEL 9 | RHEL 10 | Ubuntu / Debian |
|---|---|---|---|
| Package | redis | valkey | redis-server |
| Service | redis | valkey | redis-server |
| Config | /etc/redis/redis.conf | /etc/valkey/valkey.conf | /etc/redis/redis.conf |
| Client | redis-cli | valkey-cli | redis-cli |
| Data | /var/lib/redis/ | /var/lib/valkey/ | /var/lib/redis/ |
| Port | 6379/tcp | 6379/tcp | 6379/tcp |
Let op
Redis has no real security when it is open to the network without a password. Attackers scan the internet for port 6379 and use open servers to write SSH keys or crypto miners. Never make it public.
Install on RHEL, Rocky, Alma and Fedora
On RHEL 10: dnf -y install valkey, systemctl enable --now valkey, and valkey-cli ping. Everything below works the same — only the names change.
Install on Ubuntu and Debian
apt-get update
apt-get install -y redis-server
redis-cli ping
PONGOp het werk
For the newest Redis version use the official repository packages.redis.io, or the container redis:8 / valkey/valkey:8.
First configuration: the settings to make first
Edit the config file (RHEL 9 and Ubuntu: /etc/redis/redis.conf). Find each setting and change it:
bind 127.0.0.1 -::1
protected-mode yes
port 6379
requirepass a-very-long-random-password-here
maxmemory 512mb
maxmemory-policy allkeys-lru
appendonly yes
appendfsync everysec
supervised systemd
rename-command FLUSHALL ""
rename-command CONFIG ""| Setting | Why |
|---|---|
bind 127.0.0.1 -::1 | Listen only on this server. Add the private IP only when app servers need it. |
requirepass | Every client must AUTH first. Better: ACL users (below). |
maxmemory | Redis may use only this much RAM — the server does not run out of memory. |
maxmemory-policy allkeys-lru | For a cache: remove the least used keys when full. For queues/sessions use noeviction. |
appendonly yes | Write every change to the AOF log; lose at most 1 second of data after a crash. |
rename-command … "" | Turn off dangerous commands (empty all data, change config at runtime). |
Set the kernel settings Redis asks for in its log, and restart:
echo 'vm.overcommit_memory = 1' > /etc/sysctl.d/90-redis.conf
sysctl --system
systemctl restart redis
redis-cli -a 'a-very-long-random-password-here' --no-auth-warning ping
PONGUsers with their own passwords and limited rights (ACL, Redis 6+), instead of one shared password:
ACL SETUSER app on >app-long-password ~app:* +@read +@write -@dangerous
ACL SETUSER default off
ACL LIST
CONFIG REWRITE(Run CONFIG REWRITE before you turn the CONFIG command off, or put the users in an aclfile.)
When app servers on other machines need Redis, add the private IP to bind, and open the port only for them:
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.1.0/24" port port="6379" protocol="tcp" accept'
firewall-cmd --reloadDaily use: the commands and the real uses
redis-cli --user app --pass app-long-password
redis-cli INFO memory | grep -E 'used_memory_human|maxmemory_human|evicted'
redis-cli INFO keyspace
redis-cli --scan --pattern 'session:*' | head
redis-cli SLOWLOG GET 10
redis-cli --latency
redis-cli --bigkeys
redis-cli BGSAVEThe basic data commands:
SET page:home "<html>…" EX 300
GET page:home
TTL page:home
INCR rate:192.0.2.5
EXPIRE rate:192.0.2.5 60
LPUSH jobs '{"id":42}'
BRPOP jobs 0
HSET user:42 name Alice plan pro
HGETALL user:42Real uses at work:
- Cache for web apps and WordPress/WooCommerce (object cache), API responses.
- PHP and app sessions shared by many web servers.
- Job queues (Sidekiq, Celery, BullMQ), rate limits, counters, leaderboards.
Let op
Do not use KEYS * or MONITOR on a busy production server — they block or slow Redis. Use --scan and SLOWLOG.
Make it safe
Security checklist:
- Never public:
bindon localhost or a private IP, firewall,protected-mode yes. - ACL users with long passwords; the
defaultuser off. - Dangerous commands off or not allowed by ACL (
FLUSHALL,FLUSHDB,CONFIG,DEBUG). maxmemoryalways set.- TLS (
tls-port) when traffic goes between servers or across networks. - Keep it updated; run it as the
redisuser (the package does this).
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
NOAUTH Authentication required | A password is set. | redis-cli -a PASS or AUTH user pass; give the app the password. |
OOM command not allowed when used memory > 'maxmemory' | Memory full with policy noeviction. | Raise maxmemory, set TTLs, or use allkeys-lru for a cache. |
MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk | The disk is full or the folder is not writable. | Free disk space; check rights on /var/lib/redis. |
Could not connect … Connection refused from another server | Redis listens only on localhost, or firewall. | Add the private IP to bind, open 6379 for the app subnet. |
WARNING Memory overcommit must be enabled! in the log | Kernel setting. | vm.overcommit_memory = 1 (see above). |
| Redis is slow sometimes | Big keys, KEYS *, or saving to disk. | SLOWLOG GET, --bigkeys; appendfsync everysec. |
| Service does not start after editing | A wrong line in the config. | journalctl -u redis -n 30; fix the line. |
Next steps
- Quick how-tos: Check Redis memory and keys, Connect apps securely (ACL + TLS).
- Command page: redis-cli — every option and example.
- Redis and the other data services at work: Cache and sessions.
- Practise with Redis in a stack: Lab: web app, database and cache with Compose.
- The databases behind the cache: PostgreSQL, MySQL / MariaDB.
1Why is an open Redis port on the internet so dangerous?
Attackers can read and change all data, and use Redis to write files like SSH keys on the server.
2Which maxmemory-policy fits a cache, and which fits a job queue?
A cache: allkeys-lru. A queue or sessions: noeviction (no data may disappear).