ERROR:
Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension
I put this code on my cache.php
'default' => env('CACHE_DRIVER', 'redis'),
And those code in my controller:
$data['posts'] = cache('posts',function(){
Post::with('user')
->select('title', 'created_at', 'user_id', 'thumbnail_path', 'content')
->orderBy('created_at','desc')
->take(50)
->get();
});
Redis in Laravel In order to use Redis with Laravel, firstly yo will have to install the predis/predis package. You can install it via composer. Just run this command and you're done. Apart from this, you can also install php redis, a php extension via PECL.
Laravel supports the use of Redis, which uses caches for temporary data storage to speed up the process of performing database queries and getting feedback, which will, in turn, reduce the amount of time spent pulling up data.
What's the use of Redis in Laravel? Conceptually, you're pushing a task (or “dispatching a job”, as it's called in the Laravel ecosystem) to the Redis queue where it waits until being picked and processed. To process queues, you need to have workers that run non-stop.
Firstly, you need to make sure you have actually installed predis using composer by running this in your terminal:
composer require predis/predis
And then you need to make sure that your have this set in your .env file
REDIS_CLIENT=predis
This is covered in the docs: https://laravel.com/docs/6.x/redis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With