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.
Redis Native Command Syntax
Section titled “Redis Native Command Syntax”FLUSHALL [ASYNC | SYNC]Parameter Description
- ASYNC: Asynchronously flush databases
- SYNC: Synchronously flush databases
Detailed Explanation
Section titled “Detailed Explanation”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”.
Flush Modes
Section titled “Flush Modes”- ASYNC: Asynchronously flush databases without blocking the server
- SYNC: Synchronously flush databases, blocking the server until the operation is complete
- 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
- This command does not delete functions
- In addition to clearing all databases, this command also clears the RDB persistence file, aborts any ongoing snapshots, and saves an empty RDB file
Redisun Usage
Section titled “Redisun Usage”In redisun, the FLUSHALL command is implemented through the FlushAllCommand class and the flushAll method in the Redisun class.
Basic Usage
Section titled “Basic Usage”Redisun redisun = Redisun.create(options -> { options.setHost("localhost"); options.setPort(6379);});
// Clear all databasesboolean result = redisun.flushAll();if (result) { System.out.println("All databases cleared successfully");}History Changes
Section titled “History Changes”- Redis 4.0.0: Added ASYNC flush mode modifier
- Redis 6.2.0: Added SYNC flush mode modifier
- FLUSHALL is a dangerous command that deletes all data. Please use it with caution
- Before using in a production environment, ensure that important data has been backed up
- Asynchronous mode can reduce the impact on server performance