Skip to content

FLUSHALL

The FLUSHALL command deletes all keys from all existing databases, not just the currently selected database. This command never fails.

The time complexity of the FLUSHALL command is O(N), where N is the total number of keys in all databases.

Terminal window
FLUSHALL [ASYNC | SYNC]

Parameter Description

  • ASYNC: Asynchronously flush databases
  • SYNC: Synchronously flush databases

The FLUSHALL command is one of the most powerful commands in Redis. It clears all data in the entire Redis instance, including all keys in all databases.

By default, FLUSHALL synchronously flushes all databases. Starting from Redis 6.2, the default flush mode can be changed to asynchronous by setting the lazyfree-lazy-user-flush configuration directive to “yes”.

  • ASYNC: Asynchronously flush databases without blocking the server
  • SYNC: Synchronously flush databases, blocking the server until the operation is complete
  1. The asynchronous FLUSHALL command only deletes keys that exist at the time the command is called. Keys created during command execution will not be deleted
  2. This command does not delete functions
  3. In addition to clearing all databases, this command also clears the RDB persistence file, aborts any ongoing snapshots, and saves an empty RDB file

In redisun, the FLUSHALL command is implemented through the FlushAllCommand class and the flushAll method in the Redisun class.

Redisun redisun = Redisun.create(options -> {
options.setHost("localhost");
options.setPort(6379);
});
// Clear all databases
boolean result = redisun.flushAll();
if (result) {
System.out.println("All databases cleared successfully");
}
  • Redis 4.0.0: Added ASYNC flush mode modifier
  • Redis 6.2.0: Added SYNC flush mode modifier
  1. FLUSHALL is a dangerous command that deletes all data. Please use it with caution
  2. Before using in a production environment, ensure that important data has been backed up
  3. Asynchronous mode can reduce the impact on server performance