It is utilized by small to large applications, including Twitter, Github, StackOverflow, and many more. In some cases, you may need to reset all the databases stored in your Redis cluster and start fresh.
This article will discuss deleting all the data stored in a Redis database.
Redis Delete All Keys
The Redis FLUSHALL command lets you delete all the keys stored in the databases in the Redis instance.
For example, to delete all the keys in the database at index 0, use the command:
The command returns ok if the operation is completed successfully.
You do not need to log in to the Redis-CLI. You can run an ad-hoc command as shown below:
The FLUSHALL command is blocking. This means that you will have to wait for the flush operation to complete before running other functions on the server.
However, as of Redis version 4.0 and above, you can run a non-blocking flush operation using the ASYNC parameter.
The following example is provided:
The ASYNC parameter forces the flush operation to run in the background without blocking the server.
Delete Keys in the Current Selected Database
To only remove the keys in the selected database, use the flushdb command. An example is as shown below:
In this case, we delete all the keys in the currently selected database, database 10.
The ad-hoc command is provided below:
The previous command uses the -n parameter to specify which database to run the flushdb command.
The command also supports the asynchronous operation.
This tutorial discussed how to delete all the keys in a Redis cluster or a specific database. In addition, FLUSHALL command and the flushdb command were explained with examples provided. We hope you found this article helpful. Check the other Linux Hint articles for more tips and information.