MageSpeedTestMagento performance benchmarking
All guides

Caching · Redis

Redis Caching Setup for Magento 2

Redis is the single highest-leverage configuration change you can make on a Magento 2 store. Here's how to configure it correctly the first time.

Caching8 min read

Redis is the recommended caching backend for Magento 2 and is the single highest-leverage server-side configuration change available. Replacing file-based caching (the default before Redis is configured) with Redis typically produces a 5–10× reduction in TTFB and meaningfully improves concurrent-request handling. The catch: getting it configured correctly the first time avoids subtle, hard-to-diagnose performance issues later.

Three databases, not one

Magento has three distinct cache concerns and Redis should be configured with a separate logical database for each:

  • Default cache (db 0). Configuration cache, layout cache, block cache, collection cache — the operational caches Magento uses internally on every page render.
  • Page cache (db 1). The full-page cache that serves cacheable customer-anonymous responses without re-rendering. This is the cache that produces most of the visible TTFB improvement.
  • Sessions (db 2). Customer session data — cart contents, customer-segment data, checkout state. Storing sessions in Redis (rather than file or database) is what enables horizontal scaling.
If all three Magento caches share a single Redis database, you will see periodic mysterious slow-downs and cache flushes affecting unrelated subsystems. The default in many tutorials is to use db 0 for everything — don't.

The actual configuration

From the Magento root, run:

php bin/magento setup:config:set \
  --cache-backend=redis \
  --cache-backend-redis-server=127.0.0.1 \
  --cache-backend-redis-port=6379 \
  --cache-backend-redis-db=0 \
  --page-cache=redis \
  --page-cache-redis-server=127.0.0.1 \
  --page-cache-redis-port=6379 \
  --page-cache-redis-db=1 \
  --session-save=redis \
  --session-save-redis-host=127.0.0.1 \
  --session-save-redis-port=6379 \
  --session-save-redis-db=2 \
  --session-save-redis-persistent-id=sess-db2 \
  --session-save-redis-max-concurrency=20

php bin/magento cache:flush

How to verify it's actually working

The most common Redis-misconfiguration symptom is 'I configured Redis but the site doesn't feel any faster.' That almost always means Magento is still using file-based caching despite the config change. Three checks confirm Redis is actually doing the work:

  1. Run php bin/magento cache:status — every cache type should be 'Enabled'.
  2. Run redis-cli -n 0 dbsize for each of the three databases — the count should be non-zero and growing as you browse the site.
  3. Hit a category page in a browser with the network panel open — the X-Magento-Cache-Debug header should report HIT after the first hit. MISS on every request means the page cache isn't engaging.

Memory sizing

Redis memory grows roughly linearly with catalog size for the default cache and roughly with traffic-volume × cache-TTL for the page cache. A 30,000-SKU Magento store with reasonable traffic typically wants 2–4 GB allocated to Redis. Setting maxmemory in redis.conf and maxmemory-policy allkeys-lru protects against runaway memory consumption — without these settings, Redis can OOM the host on a particularly aggressive cache-warming run.