Redis
What is Redis?
Redis is an in-memory data store used as a cache, session store, and queue backend. It's the most common performance upgrade for PHP apps once file-based caching or array sessions stop being enough, and Laravel supports it natively.
Start Redis
- Laradock CLI
- Docker Compose
./laradock start redis
docker compose up -d redis
Stop Redis
Stopping just pauses the container; your data is safe:
- Laradock CLI
- Docker Compose
./laradock stop redis
docker compose stop redis
To delete the container entirely (the data on disk is still untouched, it lives under DATA_PATH_HOST):
- Laradock CLI
- Docker Compose
./laradock remove redis
docker compose rm -sf redis
Configuration
redis/defaults.env holds the port, and the password lives in the main .env (uncomment/edit the line under the ### REDIS section). Either can be overridden in your own .env:
| Variable | Default | What it does |
|---|---|---|
REDIS_PORT | 6379 | Host-side port Redis is published on (host:container). |
REDIS_PASSWORD | secret_redis | Passed to the container as --requirepass; set it empty to disable auth. |
Use Redis from Laravel
- In your Laravel
.env, setREDIS_HOST=redis. If that variable isn't there, editconfig/database.phpinstead and replace the default127.0.0.1withredis:'redis' => ['cluster' => false,'default' => ['host' => 'redis','port' => 6379,'database' => 0,],], - To use Redis for cache and sessions, set
CACHE_DRIVER=redisandSESSION_DRIVER=redisin.env. - Install the client:
composer require predis/predis:^1.0
- Test it from Laravel:
\Cache::store('redis')->put('Laradock', 'Awesome', 10);
Use the redis-cli
- Laradock CLI
- Docker Compose
./laradock enter redis
docker compose exec redis bash
Then start the client, authenticating if REDIS_PASSWORD is set:
redis-cli -a secret_redis
Flush all keys (clear the cache)
⚠️ This permanently deletes every key in Redis, there's no undo. Useful when stale cached data is causing bugs and you just want a clean slate:
- Laradock CLI
- Docker Compose
./laradock exec -T redis redis-cli -a secret_redis FLUSHALL
docker compose exec -T redis redis-cli -a secret_redis FLUSHALL
FLUSHALL clears every database inside Redis. To clear only the currently selected database (database => 0 by default in Laravel's config above), use FLUSHDB instead.
Check memory usage and stats
- Laradock CLI
- Docker Compose
./laradock exec -T redis redis-cli -a secret_redis INFO memory
docker compose exec -T redis redis-cli -a secret_redis INFO memory
INFO memory reports used_memory_human (current usage) and maxmemory_policy (what Redis does when it hits a memory cap, if you've set one). Swap memory for stats (INFO stats) to see hit/miss counters, or run DBSIZE for a quick key count in the current database.
Backup and restore
Redis periodically snapshots its dataset to disk as dump.rdb under /data in the container, which maps to DATA_PATH_HOST/redis/dump.rdb on your host. To back up, force an immediate snapshot, then copy that file out:
- Laradock CLI
- Docker Compose
./laradock exec -T redis redis-cli -a secret_redis SAVE
docker compose exec -T redis redis-cli -a secret_redis SAVE
cp "${DATA_PATH_HOST:-~/.laradock/data}/redis/dump.rdb" backup.rdb
Restore a snapshot by putting it back before Redis starts, since Redis only loads dump.rdb from disk on boot:
- Laradock CLI
- Docker Compose
./laradock stop redis
docker compose stop redis
cp backup.rdb "${DATA_PATH_HOST:-~/.laradock/data}/redis/dump.rdb"
- Laradock CLI
- Docker Compose
./laradock start redis
docker compose up -d redis
Start completely fresh (wipe all data)
To throw away everything (all keys, all snapshots) and start Redis from a clean, empty state (⚠️ this permanently deletes the data, back up first if you need anything):
- Laradock CLI
- Docker Compose
./laradock stop redis
./laradock remove redis
rm -rf "${DATA_PATH_HOST:-~/.laradock/data}/redis"
./laradock start redis
docker compose stop redis
docker compose rm -sf redis
rm -rf "${DATA_PATH_HOST:-~/.laradock/data}/redis"
docker compose up -d redis
DATA_PATH_HOST is whatever you have set in .env (~/.laradock/data by default), so the folder above is where Redis's dump.rdb actually lives on your machine.
Talk to this Redis from another Laradock project
Each Laradock project is its own isolated Docker network by default, so a second project's containers can't reach this Redis by container name out of the box. Easiest fix: publish the port (already done, REDIS_PORT) and have the other project connect to your host machine's address instead of redis, for example REDIS_HOST=host.docker.internal (Docker Desktop) with REDIS_PORT and REDIS_PASSWORD matching this project's values. Make sure the two projects use different REDIS_PORT values if they're both running at once, and pick different database => indexes (or a key prefix) if you don't want them to see each other's keys.
Connect from your host machine
Inside Laradock, other containers reach Redis by container name: REDIS_HOST=redis. From your own machine, connect to localhost:6379 (or your custom REDIS_PORT) with a GUI like TablePlus or RedisInsight, using REDIS_PASSWORD if set.
Common issues
NOAUTH Authentication required.REDIS_PASSWORDis set in.envbut your client isn't sending it. Pass-a <password>toredis-cli, or set the password on your Laravel Redis connection config.- App can't connect but the container is running. Confirm the app's
.envusesREDIS_HOST=redis(the container name), notlocalhostor127.0.0.1, those only work from your host machine, not from inside another container. - Port already in use on your host. Another local Redis (or another Laradock project) is already bound to
6379. ChangeREDIS_PORTin.envand restart:./laradock restart redis. - Data disappears after
docker compose down -v. Redis data lives underDATA_PATH_HOST/redis;-vremoves named volumes and, depending on your setup, can wipe it. Use./laradock stop redisif you just want to pause the container. - Cached values from a previous session/database still show up. You're probably sharing the same
database =>index across two apps or two Laradock projects. See Flush all keys above, or give each app its own database index.
Need a GUI to browse keys? See Redis WebUI. Need a Redis-compatible alternative? See Valkey or Dragonfly, or a multi-node setup, Redis Cluster. New to Laradock? Start at Getting Started.