Dragonfly Cloud is now available on the AWS Marketplace - Learn More

Question: How to Clear Redis Database?

Answer

To clear the Redis database, you have two main options:

  1. FLUSHDB: This command clears the current Redis database.
  2. FLUSHALL: This command clears all databases in the Redis instance.

Here's a brief overview of both commands and how to execute them.

1. FLUSHDB

FLUSHDB removes all keys from the currently selected database. To use this command, simply enter it in the Redis CLI:

redis-cli FLUSHDB

You can also use it via a Redis client in your programming language, such as Python with redis-py:

import redis r = redis.StrictRedis(host='localhost', port=6379, db=0) r.flushdb()

2. FLUSHALL

FLUSHALL removes all keys from all databases within the Redis instance. To use this command, enter it in the Redis CLI:

redis-cli FLUSHALL

You can also use it via a Redis client in your programming language, such as Python with redis-py:

import redis r = redis.StrictRedis(host='localhost', port=6379, db=0) r.flushall()

Note: Use these commands with caution, as they will delete data permanently.

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

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost