Skip to content
VDS · Databases

Redis: cache and queues

Installing Redis on VDS, password and binding to a local address, memory limit and eviction policy, and the difference between a cache and a queue.

Updated August 23, 2026

Redis keeps data in memory, which is why it is used for caching, sessions, counters, and task queues. On a VPS it is useful exactly as long as it fits in memory: a working set larger than the free memory is no longer a speedup but a cause of crashes.

Installation

apt update && apt install -y redis-server        # Debian, Ubuntu
dnf install -y redis                             # AlmaLinux, CentOS Stream
systemctl enable --now redis-server
redis-cli ping

A PONG response means the server is running.

Required configuration

The /etc/redis/redis.conf file:

bind 127.0.0.1
protected-mode yes
requirepass long-random-password
maxmemory 512mb
maxmemory-policy allkeys-lru
appendonly no
systemctl restart redis-server
redis-cli -a 'password' ping

Scanners find a passwordless Redis exposed to the internet within minutes and use it for mining. If your application is on the same machine, keep bind 127.0.0.1 and do not expose port 6379 to the outside. If you need external access, use only an SSH tunnel or VPN.

Memory and eviction

Set maxmemory explicitly: without it, Redis grows until the system starts killing processes. It is reasonable to give it a quarter of the tier's memory.

TierMachine memorymaxmemory
VDS-12 GB256 MB
VDS-24 GB512 MB
VDS-38 GB1–2 GB
VDS-524 GB4–6 GB

The policy depends on the role:

  • cache — allkeys-lru, old keys are evicted silently;
  • task queue — noeviction, losing a task is unacceptable, a write error is better.

Do not mix cache and queue in one database precisely because of this contradiction. Separate them into different database numbers (SELECT 1) or two instances.

Persistence to disk

By default, Redis periodically dumps a snapshot to dump.rdb. For a pure cache this is unnecessary disk writing — disable save. For queues, enable appendonly yes: that way tasks will not be lost after a machine reboot.

Keep in mind that disk write speed is limited by the tier: 60 MB/s per core, no lower than 60 and no higher than 400 MB/s.

Monitoring

redis-cli -a 'password' info memory
redis-cli -a 'password' info stats
redis-cli -a 'password' --stat
redis-cli -a 'password' slowlog get 10

The key metric is evicted_keys: constant growth means there is not enough memory and the cache is not paying off.

Common mistakes

SymptomCause
NOAUTH Authentication requiredThe application was not given the password
OOM command not allowedmaxmemory reached with the noeviction policy
DENIED Redis is running in protected modeExternal access with bind 127.0.0.1 — this is by design
Data disappeared after a rebootPersistence is not enabled
The machine went into swapThe sum of maxmemory and other services exceeds the tier's memory

Do not use KEYS * on a production server: the command blocks Redis while it iterates over all keys. Use SCAN for iteration.