How to clear the Redis cache - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to clear the Redis cache
============================

### [\#Performance](https://rocketeersapp.com/knowledge/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](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 3 minute read

1. [FLUSHDB vs FLUSHALL](#content-flushdb-vs-flushall)
2. [Clear specific keys](#content-clear-specific-keys)
3. [Async (non-blocking) flush](#content-async-non-blocking-flush)
4. [Clearing the cache from Laravel](#content-clearing-the-cache-from-laravel)
5. [A word of caution in production](#content-a-word-of-caution-in-production)
6. [Conclusion](#content-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.

[\#](#content-flushdb-vs-flushall "Permalink")FLUSHDB vs FLUSHALL
-----------------------------------------------------------------

Redis splits its keyspace into numbered databases (0 by default). The two flush commands differ in scope:

- **`FLUSHDB`** clears the *current* database only.
- **`FLUSHALL`** clears *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](/redis-connection-refused-laravel).

[\#](#content-clear-specific-keys "Permalink")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.

[\#](#content-async-non-blocking-flush "Permalink")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.

[\#](#content-clearing-the-cache-from-laravel "Permalink")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](/clear-cache-laravel) and the [Laravel cache](/laravel-cache) reference.

[\#](#content-a-word-of-caution-in-production "Permalink")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` + `DEL` instead of a full flush whenever you can.
- Warm critical keys right after flushing.
- Use `FLUSHALL ASYNC` so the flush itself doesn't block Redis.

[\#](#content-conclusion "Permalink")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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Performance](https://rocketeersapp.com/knowledge/performance)

- [How to optimize server performance](https://rocketeersapp.com/knowledge/optimize-server-performance)
- [How to optimize website performance](https://rocketeersapp.com/knowledge/optimize-website-performance)
- [How to measure TTFB (Time To First Byte)](https://rocketeersapp.com/knowledge/ttfb)
- [How to enable and configure OPcache for faster PHP](https://rocketeersapp.com/knowledge/enable-opcache-php)
- [A complete guide to caching in Laravel](https://rocketeersapp.com/knowledge/laravel-cache)
- [How database indexing works (with MySQL examples)](https://rocketeersapp.com/knowledge/database-indexing)

 [View all 13 articles →](https://rocketeersapp.com/knowledge/performance)
