Luc
Luc

Reputation: 17072

How to empty a redis database?

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 ?

Upvotes: 213

Views: 172337

Answers (7)

Flash Noob
Flash Noob

Reputation: 500

With redis-cli:

FLUSHDB [ASYNC | SYNC]

ASYNC: flushes the database asynchronously

SYNC: flushes the database synchronously

Note: an asynchronous FLUSHDB command only deletes keys that were present at the time the command was invoked. Keys created during an asynchronous flush will be unaffected.

Upvotes: 1

Dexter
Dexter

Reputation: 11831

Be careful here.

FLUSHDB deletes all keys just in the current database (0 by default), while FLUSHALL deletes all keys in all databases (on the current host).

Upvotes: 155

Marc
Marc

Reputation: 5508

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

Upvotes: 75

Denys
Denys

Reputation: 1478

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.

Upvotes: 5

behzad babaei
behzad babaei

Reputation: 1161

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.

Upvotes: 0

plaes
plaes

Reputation: 32716

You have two options:

  • FLUSHDB - clears currently active database
  • FLUSHALL - clears all the existing databases

Upvotes: 253

Hieu Le
Hieu Le

Reputation: 2136

With redis-cli:

FLUSHDB       - Removes data from your connection's CURRENT database.
FLUSHALL      - Removes data from ALL databases.

Redis Docs: FLUSHDB, FLUSHALL

Upvotes: 36

Related Questions