Knowledge
How to clear the Redis cache
#Performance
A practical guide to clear the Redis cache, from flushing a single database with redis-cli to safely deleting keys by pattern and clearing the cache from Laravel.
Published by Mark van Eijk on June 23, 2026 · 3 minute read
- FLUSHDB vs FLUSHALL
- Clear specific keys
- Async (non-blocking) flush
- Clearing the cache from Laravel
- A word of caution in production
- Conclusion
You usually clear the Redis cache after a deploy, when stale data is being served, or while debugging locally. The commands are simple, but on a shared or production instance they are destructive: a single flush wipes every cached value at once. This guide covers how to clear the Redis cache safely, from a full flush down to deleting individual keys.
FLUSHDB vs FLUSHALL
Redis splits its keyspace into numbered databases (0 by default). The two flush commands differ in scope:
FLUSHDBclears the current database only.FLUSHALLclears every database on the instance.
Connect with redis-cli and pick a database with -n:
# Clear database 0 (the default)
redis-cli FLUSHDB
# Connect to database 2, then clear it
redis-cli -n 2 FLUSHDB
# Wipe every database on the instance
redis-cli FLUSHALL
Inside an interactive session you select the database with SELECT:
redis-cli
127.0.0.1:6379> SELECT 2
OK
127.0.0.1:6379[2]> FLUSHDB
OK
If redis-cli itself can't connect, that's a separate problem, see Redis connection refused in Laravel.
Clear specific keys
Flushing is rarely what you want in production. To remove one key, use DEL:
redis-cli DEL session:abc123
redis-cli DEL user:42 user:43 user:44
To delete everything matching a pattern, you might reach for KEYS, don't. KEYS scans the entire keyspace in a single blocking operation; on a large dataset it freezes the server for the duration. Use SCAN, which iterates in small batches, and pipe the results into DEL:
redis-cli --scan --pattern 'session:*' | xargs -L 100 redis-cli DEL
--scan cursors through the keyspace without blocking, and -L 100 deletes in chunks of 100 keys so you don't build one enormous command. This is the safe way to clear the Redis cache for a subset of keys on a live instance.
Async (non-blocking) flush
FLUSHDB and FLUSHALL are synchronous by default: on a cache holding millions of keys, freeing that memory blocks the server. The ASYNC modifier hands the cleanup to a background thread so the command returns immediately:
redis-cli FLUSHDB ASYNC
redis-cli FLUSHALL ASYNC
Use ASYNC on any large production cache. The keys disappear right away; only the memory reclamation happens in the background.
Clearing the cache from Laravel
If Redis is your Laravel cache store, you rarely touch redis-cli at all. The Artisan command clears the default store:
php artisan cache:clear
The programmatic equivalent is Cache::flush():
use Illuminate\Support\Facades\Cache;
Cache::flush();
To clear a specific store instead of the default, name it:
Cache::store('redis')->flush();
php artisan cache:clear --store=redis
One caveat: flush() clears the entire store, including any non-cache data sharing that Redis database (sessions, queues). If you only want to drop tagged entries, flush by tag:
Cache::tags(['users'])->flush();
For the full set of Laravel options see clearing the cache in Laravel and the Laravel cache reference.
A word of caution in production
Clearing the cache in production isn't free. When you flush, every subsequent request misses the cache at once and falls through to the database. That sudden surge, a cache stampede or thundering herd, can overload the database hard enough to take the site down, exactly when you were trying to fix it.
To soften the impact:
- Clear specific keys with
SCAN+DELinstead of a full flush whenever you can. - Warm critical keys right after flushing.
- Use
FLUSHALL ASYNCso the flush itself doesn't block Redis.
Conclusion
To clear the Redis cache, match the tool to the blast radius: DEL or SCAN for individual keys, FLUSHDB for one database, FLUSHALL for the whole instance, and ASYNC on anything large. From Laravel, prefer php artisan cache:clear or Cache::flush(). In production, lean toward targeted deletes and be ready for the cache stampede a full flush can trigger.
Subscribe to our newsletter
Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!
Related articles
How to optimize server performance
A practical guide to clear the Redis cache, from flushing a single database with redis-cli to safely deleting keys by pattern and clearing the cache from Laravel.
How to measure TTFB (Time To First Byte)
A practical guide to clear the Redis cache, from flushing a single database with redis-cli to safely deleting keys by pattern and clearing the cache from Laravel.