I'm getting error "Class 'Predis\Client' not found" in Laravel 5.2

LaravelLaravel 5RedisComposer PhpLaravel 5.2

Laravel Problem Overview


I want to using Redis in laravel 5.2 however, I'm getting error such a Class 'Predis\Client' not found, How I can solve it.

Laravel Solutions


Solution 1 - Laravel

  1. First download the REDIS to your system (if you haven't already installed it).

  2. Go to the folder where you have downloaded the redis and run this command:

    cd your-redis-folder-name
    make
    
  3. Go to your project directory and install composer:

    composer require predis/predis

  4. Go to your .env file and add Queue driver:

    QUEUE_DRIVER=redis
    
  5. use Mail::queue() to send mail via queue. See Doc.

  6. And in your terminal run:

    php artisan queue:listen 
    

    to send.

Solution 2 - Laravel

Write in console in project folder:

composer require predis/predis

And thats all.

Solution 3 - Laravel

You need to add predis/predis into composer.json for your project. Reference: https://laravel.com/docs/5.2/redis#introduction

Solution 4 - Laravel

we have add composer.json file "predis/predis": "~1.0" help working fine.

Solution 5 - Laravel

Btw, if you are using laravel workers, with ubuntu supervisor and this error will not dissappear even after you did

composer require predis/predis

Then remember kids, that supervisor caches all your php code, once you boot it. So installing predis after you booted supervisor workers (https://laravel.com/docs/5.6/queues#supervisor-configuration), will not make a difference, until you do

sudo supervisorctl stop laravel-worker:*

and then start it again

sudo supervisorctl start laravel-worker:*

I've been stuck on this for an hour or two, on 3 projects in the last year.

Solution 6 - Laravel

Running composer dump after installing predis/predis package might be necessary

Solution 7 - Laravel

I solved the problem just including the use Predis; above class file in app folder.

If you installed predis via composer require predis/predis already.

Solution 8 - Laravel

you can also try to run Redis as a local server, download this and run the run Redis server file

if you still get it use composer require predis/predis

Solution 9 - Laravel

It's easy to just look at the path and filename Examples that exist Most of the path name or autoload file name are not spelled correctly

1-go to https://github.com/predis/predis/tags

2-create folder in host by name redis

3-download predis and upload to your website dir (www) in redis

4- create index.php out of the predis folder(redis)

5- past this code for test in index.php

require 'redis/Autoload.php';
Predis\Autoloader::register();
$client = new Predis\Client();
$client->set('foo', 'bar');
$value = $client->get('foo');
echo $value;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiononercillerView Question on Stackoverflow
Solution 1 - LaravelAbhishekView Answer on Stackoverflow
Solution 2 - LaravelKamil KiełczewskiView Answer on Stackoverflow
Solution 3 - LaravelMarcin NabiałekView Answer on Stackoverflow
Solution 4 - LaravelVinod Kumar PalView Answer on Stackoverflow
Solution 5 - LaravelKarl Johan VallnerView Answer on Stackoverflow
Solution 6 - LaravelMwatha KinyuaView Answer on Stackoverflow
Solution 7 - LaravelPeterPiView Answer on Stackoverflow
Solution 8 - LaravelEymenView Answer on Stackoverflow
Solution 9 - Laravelsadegh salehiView Answer on Stackoverflow