Why self-host Redis on a VPS
Redis lives in memory: its performance depends directly on RAM and network latency. Managed offerings charge a high price for each GB of RAM and impose connection caps. On a VPS, you size the RAM according to your real needs, you freely configure maxmemory and the eviction policy (allkeys-lru, volatile-ttl...), and you enable RDB and/or AOF persistence depending on your tolerance for data loss. For an application cache, a job broker (Sidekiq, BullMQ, Celery), or a session store, a Redis placed right next to your application on the same private network eliminates inter-datacenter latency and drastically reduces cost.
The concrete benefits of a self-hosted Redis
- Sub-millisecond latency if Redis runs on the same VPS or the same private network as your app.
- Control of
maxmemoryand the eviction policy according to your cache or job-queue use case. - Persistence of your choice: RDB (snapshots), AOF (journal), or both for durability.
- RAM cost without overcharging: you pay the VPS plan, not premium memory by the GB.
- Free modules: RediSearch, RedisJSON, RedisBloom as needed.
- No arbitrary cap on the number of simultaneous client connections.
Hardware and software prerequisites
Since Redis is in-memory, it's the RAM that matters, not the CPU. For a modest cache or a session store, 1 vCPU and 1 to 2 GB of RAM are enough — Redis open source has low CPU usage since it is single-threaded for commands (network I/O is asynchronous). If Redis serves as a broker for thousands of queued jobs or stores multi-GB in-memory datasets, size the RAM to at least twice your target maxmemory to absorb the copy-on-write during RDB snapshots: during a BGSAVE, the child process may temporarily duplicate modified pages.
On disk, plan for at least 2× the size of your dataset if you enable RDB or AOF persistence, plus space for log rotation. On the software side: Ubuntu 22.04/24.04 LTS, Docker and Compose v2, a persistent volume for AOF/RDB if you enable persistence, and the vm.overcommit_memory=1 setting on the host to avoid fork failures during backups. Disabling Transparent Huge Pages (echo never > /sys/kernel/mm/transparent_hugepage/enabled) is also recommended: Redis explicitly warns about this at startup if it is active, as it can cause latency spikes and abnormal memory consumption.
Deploying Redis with Docker in production
Prepare the host
Install Docker, then set
vm.overcommit_memory=1viasysctlto make snapshots reliable, and disable Transparent Huge Pages. Close port 6379 to the outside: a Redis exposed without a password is a classic target for cryptominers.# Persistent via sysctl.conf echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf sysctl -p # Disable THP echo never > /sys/kernel/mm/transparent_hugepage/enabledWrite the docker-compose.yml
Declare a
redis:7-alpineservice with a custom command pointing to aredis.confmounted as read-only. Enablerequirepass, setmaxmemoryandmaxmemory-policy, and mount a volume for/dataif you want persistence.services: redis: image: redis:7-alpine command: redis-server /etc/redis/redis.conf volumes: - ./redis.conf:/etc/redis/redis.conf:ro - redis_data:/data restart: unless-stopped ports: - "127.0.0.1:6379:6379" volumes: redis_data:Configure security
In
redis.conf, security rests on several complementary layers. The first is network binding:bind 127.0.0.1or your private network IP — never listen on0.0.0.0without additional protection. The second is authentication:requirepass YOUR_STRONG_PASSWORDfor Redis 6 and earlier; for Redis 7, prefer ACLs which allow creating users with granular permissions:bind 127.0.0.1 requirepass YOUR_STRONG_PASSWORD # Redis 7 ACL: read-only user for your app aclfile /etc/redis/users.acl # Disable dangerous commands rename-command FLUSHALL "" rename-command CONFIG "" rename-command DEBUG ""The
users.aclfile can declare:user app_user on >PASSWORD ~* +@read +@write -@dangerous user default offFor encrypted remote access, enable Redis native TLS (available since Redis 6):
tls-port 6380 tls-cert-file /certs/redis.crt tls-key-file /certs/redis.key tls-ca-cert-file /certs/ca.crtAlternatively, an SSH tunnel or VPN is enough for most cases without TLS complexity.
Choose the persistence strategy
Redis offers two persistence mechanisms, which can be combined.
RDB (snapshot): Redis writes a dataset snapshot to disk at configurable intervals. Fast on restart, but you lose data written since the last snapshot in case of crash.
# Snapshot if 1 key changes in 900s, 10 keys in 300s, 10000 keys in 60s save 900 1 save 300 10 save 60 10000AOF (Append-Only File): every write command is journaled. Safer, slightly slower.
appendfsync everysecis the right trade-off: at most 1 second of data lost.appendonly yes appendfsync everysec auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mbCombining RDB + AOF: on restart, Redis uses the AOF (more complete), while RDB accelerates periodic full backups. This is the recommended strategy for critical job brokers.
For a pure cache where data loss is acceptable, disable persistence:
save ""andappendonly no— you gain performance and disk space.Connect your application
Launch with
docker compose up -dand test withdocker compose exec redis redis-cli -a YOUR_PASS ping. Point your application to the internal Docker network rather than a public IP, for both latency and security.# Connectivity test docker compose exec redis redis-cli -a YOUR_PASS ping # PONG # Check active configuration docker compose exec redis redis-cli -a YOUR_PASS CONFIG GET maxmemoryFor applications on the same Docker host, use the service name as the host (
redis:6379) rather thanlocalhostor the public IP.Monitor memory
Monitor
used_memoryandevicted_keysviaredis-cli INFO. If evictions rise, increase the RAM or refine the policy. Set up an alert when memory usage exceeds 80% ofmaxmemory.# Redis health overview redis-cli -a YOUR_PASS INFO memory | grep -E 'used_memory_human|maxmemory_human|mem_fragmentation_ratio' redis-cli -a YOUR_PASS INFO stats | grep -E 'evicted_keys|keyspace_hits|keyspace_misses'A
mem_fragmentation_ratioabove 1.5 indicates significant fragmentation: aMEMORY PURGEor a rolling restart may help.Logging in for the first time
Open the URL: RedisInsight appears straight away, WITHOUT asking for any credentials at all (you only accept the terms of use on the first screen), and your local Redis database is already accessible there for reading and writing. Do not attach a public domain to this interface without protection in front of it.
Troubleshooting: the most common errors
Here are the errors you will most often encounter when running Redis on a VPS, with their cause and fix.
MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist on disk— Redis is attempting a snapshot but the fork fails. Cause:vm.overcommit_memoryis set to 0 on the host. Fix:sysctl vm.overcommit_memory=1(permanent in/etc/sysctl.conf). If you use Docker, this parameter must be set on the Docker host, not inside the container.ERR max number of clients reached— The number of simultaneous connections exceedsmaxclients(default: 10,000). Common causes: misconfigured connection pool on the application side (Sidekiq, Laravel Horizon, etc.) or unclosed connections. Fix: increasemaxclientsinredis.confand check the pool configuration on the app side. The commandredis-cli CLIENT LISTlists active connections.- OOM Killer kills the Redis process — The Linux kernel kills Redis due to lack of free memory. Cause:
maxmemorynot set or too generous, combined with the copy-on-write of the RDB fork. Fix: setmaxmemoryto 60-70% of available RAM, choose an eviction policy (maxmemory-policy allkeys-lrufor a cache,noevictionfor a broker), and plan for 2× the dataset for the RDB fork. Monitor/var/log/syslogforOut of memory: Kill processmessages. Could not create server TCP listening socket 0.0.0.0:6379: bind: Address already in use— Another process is occupying port 6379. Identify it withss -tlnp | grep 6379and stop it, or change the Redis port in your configuration. On VPS with a Redis instance installed viaapt, the system service may conflict with your Docker container.
High availability: Sentinel and Cluster
For critical workloads where Redis downtime is unacceptable, two solutions exist.
Redis Sentinel is the high-availability solution for a master/replica architecture. Deploy three Sentinel nodes on three separate VPS: Sentinel monitors the master, detects failure, and automatically promotes a replica. Your applications connect via the Sentinel service rather than directly to the master — they are transparent to the failover. Sentinel suits most cases: cache, sessions, job brokers with durability.
Redis Cluster partitions data across multiple nodes (horizontal sharding) and includes built-in high availability. It requires at minimum 6 nodes (3 masters + 3 replicas) and client-side adaptation. Reserve it for datasets exceeding a single server's RAM or workloads requiring very high write throughput.
For the vast majority of VPS use cases, Sentinel on 3 nodes is the right answer: simpler to operate, compatible with all standard Redis clients, and sufficient for datasets of a few tens of GB.
Updates and Valkey as an alternative
On versions. Redis 7.4 is the current stable LTS branch (7.4.11 at time of writing). Redis 8 is the latest major GA version, released in May 2025, which also marked the adoption of AGPLv3 as a third license option — alongside the RSALv2 and SSPLv1 adopted in March 2024. For a migration from Redis 7.x to Redis 8, consult the official release notes: behavior changes in memory management and ACLs should be anticipated.
On licensing. In March 2024, Redis Ltd. dropped the BSD 3-Clause license in favor of a dual RSALv2 + SSPLv1 license (not OSI-approved). In response, the Linux Foundation created Valkey on March 28, 2024 — a fork of Redis 7.2.4 under the BSD 3-Clause license, backed by AWS, Google Cloud, Oracle, and other founding members. Valkey follows an independent development trajectory and publishes its own releases. If your use case involves redistribution or license constraints, or if you want a 100% open-source fork in the OSI sense, Valkey is a direct alternative: APIs and protocols are compatible, and migration is generally transparent. A dedicated article compares the two projects in detail: Valkey vs Redis in 2026: should you migrate?
For common private uses (application cache, job broker, session store on your own infrastructure), Redis 7.x or 8 remains fully usable without license friction.
Monitor the keyspace_hits / keyspace_misses ratio via INFO stats: a low hit rate means your cache is undersized or your TTLs are too short. For critical workloads, deploy Redis Sentinel across three VPS to obtain automatic failover: if the master goes down, a replica is promoted without intervention, and your applications are redirected via the Sentinel service.
The official documentation
For advanced configuration and tool-specific options, refer to the official Redis documentation. This guide covers going live on a VPS; the vendor's documentation remains the reference for fine-tuning, major upgrades, and specific use cases.