Redis is a free, open-source, in-memory data store used by millions of developers as a database, cache, streaming engine, and message broker.
Redis Clear Cache with the Redis CLI
Redis provides a CLI interface that allows us to interact with the Redis server using raw commands in a terminal session.
we can use the Redis CLI commands to remove all the keys from a single or all databases in the cluster.
Redis Delete All Keys From Specific Database
In Redis, we can use the
flushdb command to remove all the keys from a specific database. The command syntax is as shown:
flushdb command without arguments will remove all the keys from the currently selected database.
To remove all the data stored in a target Redis database, use the
-n option; the syntax is as shown:
redis-cli -n [database_index] flushdb
Where the database_index is the target database ranging from 0 to 16.
Since Redis version 4.0+, we can delete keys from a given database in the background without blocking the server. This is possible using the asynchronous option specified using the
redis-cli FLUSHDB ASYNC redis-cli -n <database_index> FLUSHDB ASYNC
Redis Delete All Keys
To delete all the keys from the Redis cluster (across all databases), we can use the
FLUSHALL command as shown:
To operate asynchronously, run the following:
redis-cli flushall async
This tutorial shows how to remove all the keys from a given database. You also learned how to clear the Redis cache by removing all the data across the Redis databases.