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.1keeps Redis reachable only from the same server. This is the default in the Ubuntu and Debian packages; check it has not been changed.requirepasssets a password for the default user. For finer control, define ACL users (for example one read-only and one read-write user) withuserlines 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
| Policy | Behaviour | Use when |
|---|---|---|
allkeys-lru | Evicts least recently used keys | Pure cache (the usual choice) |
allkeys-lfu | Evicts least frequently used keys | Cache with a stable set of "hot" keys |
volatile-lru | Evicts only keys that have a TTL | Redis holds both cache data and data that must not be evicted |
noeviction | Rejects writes when full | Queues, 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 (
savelines): 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 (withappendfsync 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
| Framework | Configuration |
|---|---|
| Laravel | CACHE_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.js | createClient({ url: "redis://:PASSWORD@127.0.0.1:6379" }) with the redis package, or ioredis |
| WordPress | An 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. UseSCANinstead.
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.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
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.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check 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
| Problem | Cause 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 required | App is missing the password; update its Redis URL |
| Connection refused from another server | Redis is bound to localhost (correct default); use a private network and an IP-restricted firewall rule if you really need remote access |
| Queue jobs disappearing | Jobs share an instance with an allkeys-* eviction policy; separate queues from the cache |
| Latency spikes every few minutes | Background RDB saves on a large dataset; disable persistence for the cache or tune save intervals |
Frequently Asked Questions
How much RAM does Redis need?
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?
Is it safe to expose Redis to the internet?
Should cache and queues share one Redis instance?
volatile-lru with TTLs on all cache keys.How do I check if Redis caching is working?
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?
What is Valkey?
Why does Redis warn about overcommit_memory?
vm.overcommit_memory = 1 follows Redis's recommendation.