Question: How to Clear the Redis Cache?


To clear the Redis cache, you can use either of the following commands:

  1. FLUSHDB: This command clears the cache for the currently selected database.
  1. FLUSHALL: This command clears the cache for all databases on the Redis server.

You can issue these commands using the following methods:

Using Redis CLI

Open a terminal and execute the redis-cli command followed by the desired flush command (FLUSHDB or FLUSHALL):

redis-cli FLUSHDB


redis-cli FLUSHALL

Using a Redis Client Library

If you are using a Redis client library in your programming language, you can call the appropriate method to execute the flush command. Here is an example using Python's Redis library:

import redis # Connect to Redis r = redis.Redis(host='localhost', port=6379, db=0) # Clear the current database's cache r.flushdb() # OR to clear all databases' caches r.flushall()

Remember that clearing the cache will remove all stored data, so use these commands with caution.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book
Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.