Databases12 min read•Updated November 2026

How to Deploy Redis on a VPS for Application Caching

Quick answer

Install Redis from your distribution (sudo apt install redis-server), keep it bound to 127.0.0.1 with protected mode on, and set a password or ACL user. For a pure cache, set maxmemory (for example 1gb) and maxmemory-policy allkeys-lru so Redis evicts old keys instead of failing, and disable or relax persistence. Point your framework's cache driver at redis://127.0.0.1:6379 and watch hit rate and memory with redis-cli INFO.

Redis is an in-memory data store that answers in well under a millisecond, which makes it the standard choice for caching database queries, rendered fragments and sessions. A cache in front of a busy database can cut response times and database load dramatically. The catch is that Redis keeps everything in RAM and, out of the box, is easy to misconfigure: without a memory limit it can grow until the server runs out of memory, and an exposed Redis is one of the most commonly attacked services on the internet.

Step 1: Install Redis

sudo apt update
sudo apt install -y redis-server
redis-server --version
sudo systemctl enable --now redis-server
redis-cli ping     # PONG

The packaged version is fine for caching. If you need features from a newer release, Redis publishes its own apt repository. Note that recent Redis releases changed licence terms; if that matters to you, Valkey is a compatible open-source fork packaged by several distributions, and everything in this guide applies to it.

Step 2: Keep Redis Private and Authenticated

Edit /etc/redis/redis.conf:

bind 127.0.0.1 -::1
protected-mode yes
port 6379
requirepass use-a-long-random-password
  • bind 127.0.0.1 keeps Redis reachable only from the same server. This is the default in the Ubuntu and Debian packages; check it has not been changed.
  • requirepass sets a password for the default user. For finer control, define ACL users (for example one read-only and one read-write user) with user lines or an ACL file.
  • Never open port 6379 in your firewall to the internet. If an app on another server needs Redis, allow only that server's IP, or use a private network or a VPN tunnel.
  • Consider disabling dangerous commands for the application user with ACLs (for example FLUSHALL, CONFIG, KEYS).
sudo systemctl restart redis-server
redis-cli -a 'use-a-long-random-password' ping

Avoid passing the password with -a in scripts (it appears in the process list and shell history); use the REDISCLI_AUTH environment variable instead.

Step 3: Set a Memory Limit and Eviction Policy

This is the most important setting for a cache. Without maxmemory, Redis grows until the operating system runs out of memory. With it, Redis evicts keys according to the policy you choose:

maxmemory 1gb
maxmemory-policy allkeys-lru
PolicyBehaviourUse when
allkeys-lruEvicts least recently used keysPure cache (the usual choice)
allkeys-lfuEvicts least frequently used keysCache with a stable set of "hot" keys
volatile-lruEvicts only keys that have a TTLRedis holds both cache data and data that must not be evicted
noevictionRejects writes when fullQueues, sessions or data you cannot lose

If the same Redis instance also holds queues (Laravel, Celery, BullMQ) or sessions, do not use an allkeys-* policy: evicted jobs are lost jobs. Run a separate instance for the cache, or use volatile-lru and give every cache key a TTL.

Leave headroom: Redis uses some memory beyond maxmemory for buffers and fragmentation, and a background save can temporarily need more. On an 8 GB server running an app and a database, 1–2 GB for the cache is a sensible start.

Step 4: Choose Persistence

Redis can save data to disk in two ways:

  • RDB snapshots (save lines): periodic point-in-time dumps. Compact, fast restarts, but writes since the last snapshot are lost on a crash.
  • AOF (appendonly yes): logs every write. Much less data loss (with appendfsync everysec, at most about a second), more disk I/O.

For a pure cache, persistence is optional: the data can always be rebuilt from the database. Disabling it (save "" and appendonly no) saves disk I/O and avoids memory spikes during background saves. For queues and sessions, enable AOF.

Step 5: Kernel Settings Redis Asks For

Check the log after starting: journalctl -u redis-server or /var/log/redis/redis-server.log. Redis warns about settings that affect reliability. The most common is memory overcommit, which background saves rely on:

echo 'vm.overcommit_memory = 1' | sudo tee /etc/sysctl.d/99-redis.conf
sudo sysctl --system

Follow the specific recommendations your Redis version prints (for example about transparent huge pages) rather than applying settings blindly.

Step 6: Connect Your Application

FrameworkConfiguration
LaravelCACHE_STORE=redis, REDIS_HOST=127.0.0.1, REDIS_PASSWORD=... (install php-redis or use predis)
Django 4.0+CACHES = {"default": {"BACKEND": "django.core.cache.backends.redis.RedisCache", "LOCATION": "redis://:PASSWORD@127.0.0.1:6379/1"}}
Node.jscreateClient({ url: "redis://:PASSWORD@127.0.0.1:6379" }) with the redis package, or ioredis
WordPressAn object-cache plugin pointed at 127.0.0.1:6379

Use separate database numbers (or better, separate instances) for cache and queues, and always set a TTL on cache keys so stale data expires even if eviction never triggers.

Caching Patterns That Work

  • Cache-aside: read from Redis; on a miss, query the database, store the result with a TTL, return it. Invalidate or update the key when the underlying data changes.
  • Short TTLs for hot data: even 30–60 seconds of caching can absorb traffic spikes on popular pages.
  • Prevent stampedes: when a popular key expires, many requests may rebuild it at once. Use a short lock, or refresh the value before it expires.
  • Avoid KEYS * in production: it blocks Redis while scanning every key. Use SCAN instead.

Step 7: Monitor Hit Rate and Memory

redis-cli INFO memory | grep -E 'used_memory_human|maxmemory_human|mem_fragmentation_ratio'
redis-cli INFO stats  | grep -E 'keyspace_hits|keyspace_misses|evicted_keys'
redis-cli --latency

Hit rate is keyspace_hits / (keyspace_hits + keyspace_misses). A low hit rate means you cache the wrong things or TTLs are too short. Steadily rising evicted_keys means the cache is too small for your working set: raise maxmemory if the server has room, or move to a plan with more RAM.

SkyRainCloud Plans for This Workload

Redis keeps everything in RAM, so memory is the deciding factor. Give the cache a fixed share with maxmemory and leave room for the application and database: 8 GB plans suit a cache of 1–2 GB; larger caches belong on 16 GB or 32 GB plans.

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — AMD28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthWebsites, small APIs, bots, staging and VPN serversOrder
VPS 2 — AMD416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,299/monthWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
VPS 3 — AMD832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,499/monthProduction databases, high-traffic sites, multi-container appsOrder
VPS 4 — AMD1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,899/monthLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Troubleshooting

ProblemCause and fix
OOM command not allowed when used memory > 'maxmemory'Policy is noeviction and the instance is full; raise maxmemory or use an eviction policy for cache data
NOAUTH Authentication requiredApp is missing the password; update its Redis URL
Connection refused from another serverRedis is bound to localhost (correct default); use a private network and an IP-restricted firewall rule if you really need remote access
Queue jobs disappearingJobs share an instance with an allkeys-* eviction policy; separate queues from the cache
Latency spikes every few minutesBackground RDB saves on a large dataset; disable persistence for the cache or tune save intervals

Frequently Asked Questions

How much RAM does Redis need?
As much as the data you keep in it plus overhead for buffers and fragmentation. For a cache, set maxmemory to a fixed size such as 1–2 GB on an 8 GB server and let eviction keep it within that limit.
What is the best maxmemory-policy for a cache?
allkeys-lru for a pure cache. Use volatile-lru or noeviction if the same instance holds data you must not lose, such as queues or sessions.
Do I need persistence for a Redis cache?
No. Cache data can be rebuilt from the database, so you can disable RDB and AOF to save disk I/O. Enable AOF if Redis also stores queues or sessions.
Is it safe to expose Redis to the internet?
No. Keep it bound to 127.0.0.1 with a password or ACLs. Exposed Redis instances are routinely attacked. Use a private network and an IP-restricted firewall rule if another server needs access.
Should cache and queues share one Redis instance?
Preferably not. A cache wants eviction; queues must never lose data. Run two instances, or use volatile-lru with TTLs on all cache keys.
How do I check if Redis caching is working?
Compare keyspace_hits and keyspace_misses in redis-cli INFO stats. A high hit rate and lower database load mean the cache is effective.
Redis or Memcached for caching?
Both are fast caches. Redis adds data structures, optional persistence and pub/sub, and is supported by most frameworks out of the box, which is why it is the more common choice today.
What is Valkey?
An open-source fork of Redis created after Redis changed its licence. It is protocol-compatible, so the configuration and clients in this guide work with it.
Why does Redis warn about overcommit_memory?
Background saves fork the Redis process; with strict overcommit the fork can fail under memory pressure. Setting vm.overcommit_memory = 1 follows Redis's recommendation.
Which SkyRainCloud plan should I use for Redis?
Choose by memory. An app, database and a 1–2 GB cache fit the 8 GB plans; larger caches or a dedicated Redis server suit the 16 GB or 32 GB AMD EPYC and Intel plans.
Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning