Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

FLUSHDB

FLUSHDB removes all keys from the currently selected Redis database. Use ASYNC or SYNC to choose asynchronous or synchronous flushing.

Since
Redis Open Source 1.0.0

How it works

FLUSHDB removes every key from the currently selected Redis database. It runs synchronously by default unless configuration changes the default, and ASYNC or SYNC can explicitly choose the execution mode.

Syntax

FLUSHDB [ASYNC | SYNC]

Parameters

NameTypeDescription
ASYNC | SYNCkeywordOptional flush mode: ASYNC performs asynchronous deletion; SYNC performs synchronous deletion. The default is controlled by lazyfree-lazy-user-flush.

Returns

Simple string reply: OK.

Key points

  • The command clears every key in the logical database selected by the connection.
  • The documentation states that FLUSHDB never fails.
  • Unless configuration changes the default, the server completes the deletion synchronously.
  • From Redis 6.2 onward, lazyfree-lazy-user-flush=yes changes an unspecified mode to asynchronous.
  • The optional mode explicitly chooses asynchronous or synchronous flushing.
  • Its time complexity grows linearly with the number of keys in the selected database.

Common mistakes

  • With ASYNC, keys created after the command starts are not removed.
  • Stored functions are not removed by FLUSHDB.
  • In Redis Cluster, FLUSHDB has the same scope as FLUSHALL because only database 0 exists.

Example: Asynchronously clear the selected database

redis-cli FLUSHDB ASYNC

Removes the keys that existed in the selected database when the asynchronous flush began; keys added afterward are retained.

When to use it

Reset test data

Clear an isolated logical database during development or testing.

Invalidate a cache database

Remove all cached entries from the selected database when invalidating a cache namespace.

Asynchronous bulk cleanup

Choose nonblocking deletion for a large keyspace when immediate completion is unnecessary.

Interview questions

QWhat does FLUSHDB do, and what does it return?

FLUSHDB deletes all keys in the currently selected database and returns the simple string reply OK. Its time complexity is O(N), where N is the number of keys in that database.

Follow-up: What does ASYNC change? It starts an asynchronous flush and only targets keys present when the command was invoked; later-created keys remain.

QHow do SYNC, ASYNC, and the default mode differ?

The syntax is FLUSHDB [ASYNC | SYNC]. ASYNC performs the flush asynchronously, while SYNC performs it synchronously; without an option, the default is controlled by lazyfree-lazy-user-flush.

Follow-up: How could the default behavior change without changing the command text? Set lazyfree-lazy-user-flush to yes, which makes the default asynchronous starting with Redis 6.2.

QHow does FLUSHDB behave in Redis Cluster?

Redis Cluster supports only database ID zero, so FLUSHDB is identical to FLUSHALL there. In a non-clustered server, it affects the currently selected database.

Follow-up: Why should cluster scope be treated carefully? The command's effective scope is the cluster's supported database context rather than one of several selectable logical databases.

  • FLUSHALL
  • SELECT
  • SWAPDB
  • lazyfree-lazy-user-flush

Source: FLUSHDB | Docs - Redis. Checked 2026-10-16.