Search code examples
phplaravelcachingredislaravel-5.7

Delete Redis Keys matching a pattern Laravel 5.7


I have been searching and tried multiple solution but could got any helping results, I want to clear/delete all keys matching pattern products:*.

Following are the things i have tried.

Redis::del('products:*');
Redis::del('*products:*');
Redis::del('*products*');

But nothing worked.

It is deleting key if i provide exact key name like : Redis::del('products:2:3:45');

Key are being generated like this: products:1:4:45

I have read documentation but could find anything regarding my query.

Please help.


Solution

  • You can't delete by pattern. But you can get all the keys by this pattern and then delete them:

    Redis::del(Redis::keys('products:*'));
    

    See more here.