How to get all redis keys in cache in laravel?

Member

by deron , in category: PHP Frameworks , 5 months ago

How to get all redis keys in cache in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , 5 months ago

@deron 

In Laravel, you can use the keys method of the Redis facade to retrieve all keys stored in the cache. Here's an example of how you can get all Redis keys in cache in Laravel:

1
2
3
use IlluminateSupportFacadesRedis;

$keys = Redis::keys('*');


In this code snippet, Redis::keys('*') will retrieve all keys stored in the Redis cache. The '*' pattern means that it will match all keys. You can also use a specific pattern to filter keys based on a certain criteria.


After executing the above code, the $keys variable will contain an array of all keys in the Redis cache. You can then use this array to perform any further operations or processing.