Question: How to Clear Redis Database?
Answer
To clear the Redis database, you have two main options:
FLUSHDB
: This command clears the current Redis database.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?
Other Common Redis Questions (and Answers)
- What is the default port used by Redis?
- How to start Redis server?
- Is Redis persistent?
- How fast is Redis?
- How to install Redis on Mac?
- How to check if Redis is running?
- How to restart Redis?
- Does Redis persist data?
- How to install Redis on Ubuntu?
- How to stop Redis server?
- How to see Redis version?
- Does Redis have tables?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
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