Redis as a local cache and queue service
Design and boundaries
Redis is appropriate for cache entries, sessions, queues and short-lived application state. It is not a replacement for MariaDB, backups, or permanent user data.
The intended topology is: the PHP application and Redis run on the same VPS, and the application connects through 127.0.0.1:6379 or the local Unix socket.
Install and start Redis
apt update
apt -y install redis-server
systemctl enable --now redis-server
systemctl --no-pager status redis-server
redis-server --versionDebian manages the service as redis-server.service. Do not run an additional manually downloaded Redis daemon on the same port.
Keep the listener local
Check the active listener before connecting an application:
ss -lntp | grep 6379
grep -E '^(bind|protected-mode|port|unixsocket)' /etc/redis/redis.conf | grep -v '^#' || trueThe expected TCP binding is 127.0.0.1:6379 and, where enabled, [::1]:6379. Keep protected-mode yes. If a local Unix socket is preferred, create a dedicated group and grant only the web application’s service account access to it.
Set memory policy and persistence deliberately
Redis uses RAM. Before setting a limit, reserve memory for Apache/PHP-FPM, MariaDB, Elasticsearch and the operating system. A cache-only deployment usually uses an eviction policy; a queue/session deployment often needs persistence as well.
redis-cli INFO memory
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy
redis-cli CONFIG GET appendonly
redis-cli CONFIG GET saveExample cache policy — adapt the size to the VPS after observing actual memory use:
cat >/etc/redis/conf.d/99-application-cache.conf <<'EOF'
maxmemory 256mb
maxmemory-policy allkeys-lru
EOF
systemctl restart redis-server
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policyConnect PHP applications
Install the matching PHP Redis extension for every PHP-FPM version used by an application:
apt -y install php8.1-redis php8.4-redis php8.5-redis
systemctl restart php8.1-fpm php8.4-fpm php8.5-fpm
php8.4 -m | grep -i redisApplication configuration should use host 127.0.0.1, port 6379, a prefix unique to the application/environment, and a short connection timeout. A prefix prevents unrelated sites from overwriting each other’s cache keys.
Verify from the VPS
redis-cli ping
redis-cli SET redis-guide:test "$(date -Is)" EX 60
redis-cli GET redis-guide:test
redis-cli INFO keyspace
redis-cli ACL LISTThe first command must return PONG. The temporary test key expires after 60 seconds. Remove it manually if required with redis-cli DEL redis-guide:test.
Operations and incident checks
systemctl is-active redis-server
redis-cli INFO memory
redis-cli INFO persistence
redis-cli SLOWLOG GET 10
journalctl -u redis-server -n 100 --no-pager- Monitor memory use, evicted keys, rejected connections and persistence failures.
- Restart Redis only after understanding the impact on cache, sessions and active queues.
- Back up Redis data only when the selected persistence mode makes that meaningful.
- Apply Debian security updates and test application behaviour after Redis upgrades.
Result: a private, monitored Redis instance available only to applications on this VPS.
There's nothing here.
No comments have been posted here yet.