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

# OR to clear all databases' caches

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

Start building today

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