Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Redis with Laravel: Do I use the Cache driver, or the Redis class?

I was looking at the Laravel docs and I see a cache driver and a redis class. Looking at the cache class it seems like I could just use this to store things in Redis as I just change which driver I am using for caching to the already added Redis driver. However there is also a separate Redis class. Why is there a separate redis class? If the cache class can do the same thing and allow me to also swap which driver I use if ever needed, what reason is there to use the Redis class?

Maybe I am missing something here but I am just confused which one I want to use to store key's and data in redis? I am using Laravel 5.

like image 577
ComputerLocus Avatar asked Feb 10 '23 19:02

ComputerLocus


1 Answers

From the documentation, the Cache class (Facade):

provides a unified API for various caching systems.

One of which is Redis. Another is Memcache. This class serves as a wrapper to abstract functionality to allow you to be technology agnostic. Ideally so you can swap out the underlying caching system without changing application code.

However, by abstracting you can lose functionality specific to a technology. So the Redis class is specific to Redis. If you require Redis specific functionality, you'd need to use this class directly.

like image 158
Jason McCreary Avatar answered Feb 15 '23 10:02

Jason McCreary