How to empty a redis database?
DatabaseNosqlRedisDatabase Problem Overview
I've been playing with redis (and add some fun with it) during the last fews days and I'd like to know if there is a way to empty the db (remove the sets, the existing key....) easily.
During my tests, I created several sets with a lot of members, even created sets that I do not remember the name (how can I list those guys though ?).
Any idea about how to get rid of all of them ?
Database Solutions
Solution 1 - Database
You have two options:
Solution 2 - Database
Be careful here.
FlushDB deletes all keys in the current database while FlushALL deletes all keys in all databases on the current host.
Solution 3 - Database
tldr: flushdb
clears one database and flushall
clears all databases
Clear CURRENT
Delete default or currently selected database (usually `0) with
redis-cli flushdb
Clear SPECIFIC
Delete specific redis database with (e.g. 8
as my target database):
redis-cli -n 8 flushdb
Clear ALL
Delete all redis databases with
redis-cli flushall
Solution 4 - Database
With redis-cli
:
FLUSHDB - Removes data from your connection's CURRENT database.
FLUSHALL - Removes data from ALL databases.
Solution 5 - Database
There are right answers but I just want to add one more option (requires downtime):
- Stop Redis.
- Delete RDB file (find location in redis.conf).
- Start Redis.
Solution 6 - Database
open your Redis cli and There two possible option that you could use:
FLUSHDB - Delete all the keys of the currently selected DB. FLUSHALL - Delete all the keys of all the existing databases, not just the currently selected one.