How to empty a redis database?

DatabaseNosqlRedis

Database 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:

  • FLUSHDB - clears currently active database

  • FLUSHALL - clears all the existing databases

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.

Redis Docs: FLUSHDB, FLUSHALL

Solution 5 - Database

There are right answers but I just want to add one more option (requires downtime):

  1. Stop Redis.
  2. Delete RDB file (find location in redis.conf).
  3. 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLucView Question on Stackoverflow
Solution 1 - DatabaseplaesView Answer on Stackoverflow
Solution 2 - DatabaseDexterView Answer on Stackoverflow
Solution 3 - DatabaseMarcView Answer on Stackoverflow
Solution 4 - DatabaseHieu LeView Answer on Stackoverflow
Solution 5 - DatabaseDenysView Answer on Stackoverflow
Solution 6 - Databasebehzad babaeiView Answer on Stackoverflow