Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I'm try to use redis on my project laravel 6.x it show this error message

ERROR:

Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension

image

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();
});
like image 316
Tarik Manoar Avatar asked Oct 12 '19 13:10

Tarik Manoar


People also ask

How connect laravel to Redis?

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.

How Redis works in laravel?

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.

Is there any relation between Redis and laravel queues?

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.


1 Answers

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

like image 125
blessing Avatar answered Oct 03 '22 09:10

blessing