List Magento cache keys in Redis CLI
View and understand Magento cache key patterns using Redis CLI commands.
Lesson Content
Let's look at how Magento organizes its cache keys in Redis.
First, let's open up terminal and connect to it using the Redis CLI command:
redis-cliIf you are using Docker, be sure to connect to the container first and then execute the redis-cli command. Ex:
docker-compose exec redis redis-cli
Once connected to Redis, we can view entries using the KEYS keyword.
Use a simple asterisk to return all entries in the Redis database:
KEYS *Or, we can specify a certain pattern, such as the zc prefix to return all entries related to Magento.
KEYS zc:*You’ll see something like this:
1) "zc:ti:69d_DB_PDO_MYSQL_DDL"
2) "zc:k:69d_SYSTEM_WEBSITES_BASE"
3) "zc:k:69d_BLOCK_71E8EF50FDE5DC1FC850CB9E158E8B3B"Let's break down how Magento names and structures these cache entries.
First, all Magento cache entries start with zc:, which stands for "Zend Cache", the name of Magento’s underlying cache framework.
After the zc: prefix, entries will have one of two types:
k:means "key", and contains the actual cached contentti:means "tags index", and stores cache tags that group related cache items together
The final part of each entry (69d_EAV_ATTRIBUTE) looks a bit random, but consists of:
A cache ID prefix that’s unique to your specific Magento instance. In this case, it is
69d.Then an underscore, followed by the actual cache identifier, like
EAV_ATTRIBUTEorCAT_C_3.
The exact entries you'll see depend on your specific Magento setup and what's currently cached, but they'll always follow these same patterns.
When you're done exploring, just type exit and hit Enter to exit the Redis CLI.