Reset test data
Clear an isolated logical database during development or testing.
Redis · Command
FLUSHDB removes all keys from the currently selected Redis database. Use ASYNC or SYNC to choose asynchronous or synchronous flushing.
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.
FLUSHDB [ASYNC | SYNC]| Name | Type | Description |
|---|---|---|
ASYNC | SYNC | keyword | Optional flush mode: ASYNC performs asynchronous deletion; SYNC performs synchronous deletion. The default is controlled by lazyfree-lazy-user-flush. |
Simple string reply: OK.
redis-cli FLUSHDB ASYNCRemoves the keys that existed in the selected database when the asynchronous flush began; keys added afterward are retained.
Clear an isolated logical database during development or testing.
Remove all cached entries from the selected database when invalidating a cache namespace.
Choose nonblocking deletion for a large keyspace when immediate completion is unnecessary.
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.
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.
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.
FLUSHALLSELECTSWAPDBlazyfree-lazy-user-flush