我在 Laravel 5.2 中收到错误“找不到类‘Predis\Client’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34865064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:14:30  来源:igfitidea点击:

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

laravellaravel-5rediscomposer-phplaravel-5.2

提问by onerciller

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 5.2 中使用 Redis 但是,我收到错误,例如找不到“Predis\Client”类,我该如何解决。

回答by Abhishek

  1. First download the REDISto 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.

  1. 首先将REDIS下载到您的系统(如果您还没有安装它)。
  2. 转到您下载 redis 的文件夹并运行以下命令:

    cd your-redis-folder-name
    make
    
  3. 转到您的项目目录并安装 Composer:

    composer require predis/predis

  4. 转到您的 .env 文件并添加队列驱动程序:

    QUEUE_DRIVER=redis
    
  5. 用于Mail::queue()通过队列发送邮件。见文档
  6. 在你的终端运行:

    php artisan queue:listen 
    

    发送。

回答by Kamil Kie?czewski

Write in console in project folder:

在项目文件夹中的控制台中写入:

composer require predis/predis

And thats all.

就这样。

回答by Marcin Nabia?ek

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

你需要为你的项目添加predis/predis进去composer.json。参考:https: //laravel.com/docs/5.2/redis#introduction

回答by Vinod Kumar Pal

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

我们添加了 composer.json 文件 "predis/predis": "~1.0" 帮助工作正常。

回答by Karl Johan Vallner

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

顺便说一句,如果您使用的是 laravel 工作人员,则与 ubuntu 主管一起使用,即使您这样做,此错误也不会消失

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

然后记住孩子们,一旦你启动它,主管就会缓存你所有的 php 代码。因此,在您启动主管工作人员(https://laravel.com/docs/5.6/queues#supervisor-configuration)后安装 predis不会产生任何影响,直到您这样做

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.

去年,我在 3 个项目上被困在这个问题上一两个小时。

回答by Mwatha Kinyua

Running composer dumpafter installing predis/predis package might be necessary

composer dump可能需要在安装 predis/predis 包后运行

回答by PeterPi

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

我解决了这个问题,只是use Predis;在 app 文件夹中包含了上面的类文件。

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

如果您通过 composer 安装了 predis,则需要 predis/predis。