Redis is an open-source in-memory database written in C and is optimized for speed. It is also known as a data structure server as its core data types match the programming languages’ data types, including strings, lists, dictionaries, sets, and sorted sets.
Redis is used for caching as it caches the frequently requested data in memory. It improved the speed and responsiveness of the application.
You can designate the duration of caching and data flow; hence, Redis is a popular distributed caching engine.
Redis on Magento 2
Redis is commonly used on Magento stores for object caching to stabilize the store’s performance. Magento is a popular eCommerce platform used by high-traffic websites and brands.
Redis enables fast back-end caching with cache tag support, so it is also recommended for multi-server hosting.
If you are utilizing Redis for your Magento store, congrats!
Clearing Magento 2 Redis cache, however, is not a one-click solution. Let’s see how to flush the Redis cache.
Flushing Magento Redis Cache
First, make sure that SSH is enabled and you have an active connection with the server. From there, you can use CLI to clear the Redis cache.
If you are on Breeze, you can find the SSH credentials from the dashboard.
Caution: Clearing Redis may affect the object and page caching. Please discuss with the Breeze support team before clearing the Redis cache. Send a message through live chat.
Clear Redis Cache with the Redis-CLI Command
CLI command is the easiest and quickest way to clear Redis cache.
Redis stores the databases separately. You can run different commands to clear keys from the entire database or any single database.
Redis-cli Command Syntax:
The syntax to delete Redis database cache:
redis-cli [database number] [option]
- [option]: Enter the databases to delete: Entire or anyone specific database.
- [database number]: Enter the number of the database you want to clear.
How to Delete All Keys?
Delete all the keys from Redis databases at once by using the following command:
In updated Redis 4.0.0, you have to async the process using async parameters in the syntax to avoid blocking the server while deleting the keys.
Redis-CLI flushall async
This is how you delete all the keys from databases.
Deleting Keys from a Specific Database
If you want to clear any single specific database, run the following command:
Use the ‘flushdb’ command without any parameters to clear the database you have selected.
To specify a database with a number, you can use -n parameters.
redis-cli -n [database number] flushdb
Using the Async function will clear the keys in the background without blocking the server. You can use this function with the -n parameter.
redis-cli -n [database number] flushdb async
In this quick tutorial, you learned to clear Redis Cache with CLI. You can use the CLI commands to flush the Redis cache.
For more information, you can read Redis docs.
If you encounter any problem, please leave it in the comment section. And if you are with Breeze, send us the message using live chat.