Connor Leech
Connor Leech

Reputation: 18833

Why does cache:clear not wipe all Redis keys in Laravel?

I'm trying to figure out how the php artisan cache:clear command works in relation to my Redis data store. I can store keys in Redis and run cache:clear and the Redis keys are not wiped, even though I'm using Redis as my cache.

For example I can set a key like:

Redis::set('foo', 'bar');
Redis::get('foo'); // bar

Listing out the keys with Cache::getRedis()->keys("*"); will even show my "foo" key. These persist even if I clear the cache with php artisan cache:clear.

My question is if the cache:clear command doesn't delete my Redis data what does it do? Are there any commands in Laravel that I need to watch out for if I do use Redis as a data store? I don't want to rely on Redis data but then wipe it on accident..

Upvotes: 0

Views: 1976

Answers (1)

Kenny Horna
Kenny Horna

Reputation: 14241

If you are using Redis as your cache driver, then to set keys use the Cache facade directly

use Illuminate\Support\Facades\Cache;


Cache::put('key', 'value');

Ps: To clear the cache keys of your app you can use Cache::flush();

As far as I understand, Laravel prefix all the values stored with a config key. So, this may explain why after you clearing the cache it still have your values set while using the Redis class instead.

Upvotes: 1

Related Questions