32

Laravel 版本:7.5.0 PHP 版本:7.2 数据库驱动和版本:Redis

一切正常,但突然出现此错误,我将 phpredis 更改为 predis,但错误相同。

重现步骤:我正在调用事件函数event(new ChatsEvent($data));

LogicException: Please make sure the PHP Redis extension is installed and enabled. in /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:76
Stack trace:
#0 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Support/helpers.php(428): Illuminate\Redis\Connectors\PhpRedisConnector->Illuminate\Redis\Connectors\{closure}(Object(Illuminate\Support\Facades\Redis))
#1 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(104): tap(Object(Illuminate\Support\Facades\Redis), Object(Closure))
#2 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(27): Illuminate\Redis\Connectors\PhpRedisConnector->createClient(Array)
#3 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(31): Illuminate\Redis\Connectors\PhpRedisConnector->Illuminate\Redis\Connectors\{closure}()
#4 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(111): Illuminate\Redis\Connectors\PhpRedisConnector->connect(Array, Array)
#5 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(90): Illuminate\Redis\RedisManager->resolve('default')
#6 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php(108): Illuminate\Redis\RedisManager->connection('default')
#7 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(64): Illuminate\Broadcasting\Broadcasters\RedisBroadcaster->broadcast(Array, 'ChatsEvent', Array)
#8 [internal function]: Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\RedisBroadcaster))
#9 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#10 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#11 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#12 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#13 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#14 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#15 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#16 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#17 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#18 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(83): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEvent), false)
#19 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#20 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#21 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(85): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#22 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Broadcasting\BroadcastEvent))
#23 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#24 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): Illuminate\Queue\Jobs\Job->fire()
#25 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(306): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#26 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(132): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#27 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#28 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#29 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#30 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#31 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#32 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#33 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#34 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#35 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\Container\Container->call(Array)
#36 /home/user/public_html/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#37 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#38 /home/user/public_html/vendor/symfony/console/Application.php(912): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /home/user/public_html/vendor/symfony/console/Application.php(264): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /home/user/public_html/vendor/symfony/console/Application.php(140): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#42 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#43 /home/user/public_html/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#44 {main}
4

10 回答 10

49

如果您使用 安装 Redis composer require predis/predis,则需要将此行添加到.env文件中:

REDIS_CLIENT=predis

然后通过运行以下命令清除缓存:php artisan optimize:clear


An additional wayconfig/database.php您可以在文件中更改此行:

从:

'client' => env('REDIS_CLIENT', 'phpredis'),

至:

'client' => env('REDIS_CLIENT', 'predis'),

然后通过运行以下命令清除缓存:php artisan optimize:clear

于 2020-08-03T21:05:09.940 回答
13

缺少 PHP redis 扩展。

有两种方法:

  1. 安装php redis扩展(回答https://stackoverflow.com/a/61325340/3578207
  2. 将驱动程序更改为 predis(REDIS_CLIENT在 .env 中)并安装 predis composer包(composer require predis/predis)。

predis慢了一点phpredis

PS:(对于方式 1):安装 phpredis 扩展后,您需要将其添加composer.jsonrequire部分中以"ext-redis": "*"进行正确部署。请参阅作曲家平台要求

于 2020-05-07T18:07:13.623 回答
12

对于我的情况,我只是在下面的 ubuntu 服务器中安装 php 扩展

sudo apt-get install php-redis
于 2020-08-12T08:18:29.130 回答
11

如果您在 Windows 中,请使用此composer require predis/predis命令添加 predis 的依赖项。然后像这样配置你的 .env 文件

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

我正在使用redis来排队我的邮件。所以我设置了。当你在本地开发时QUEUE_CONNECTION=redisREDIS_CLIENT=predis这很好用。在生产中它相同但有点不同

于 2020-06-20T05:45:58.097 回答
5

我有一些问题伙计,但我已经解决了这个问题。尝试学习(我的操作系统是 Linux):

第 1 步:安装 PhpRedis 为了安装最新版本的 PhpRedis 扩展,我们可以使用 pecl。要安装 pecl,您需要安装 PHP Extension and Application Repository 或简称 PEAR:

sudo apt install php-pear

第 2 步:然后您可能还需要安装 PHP 开发工具:

sudo apt install php-dev

第 3 步:然后我们要继续在此处安装此软件包。为此,只需运行:

sudo pecl install redis

最后:确保通过将以下行添加到您的 php.ini 来启用新的 PHP 扩展,如果没有找到此脚本,您可以在所有列表下编写此脚本extension=

extension = redis.io

并且不要忘记通过以下方式重新启动您的 apache2 服务:

sudo service apache2 restart

祝你好运伙计!

于 2020-04-20T14:49:41.703 回答
1

我总是遇到php7.x-dev像这样安装的麻烦

The following packages have unmet dependencies:
 php7.3-dev : Depends: libpcre2-dev (>= 10.30) but it is not going to be installed
              Depends: libssl-dev but it is not going to be installed
              Depends: php7.3-common (= 7.3.11-0ubuntu0.19.10.6) but 7.3.20-1+ubuntu19.10.1+deb.sury.org+1 is to be installed
              Recommends: pkg-php-tools but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

所以我跳过php7.x-dev安装直接去sudo pecl install redis然后我得到了新的错误:

sh: 1: phpize: not found
ERROR: `phpize' failed

我最终搜索安装phpize,解决方案是安装php-dev.

对于那些像我一样有类似问题的人。而不是sudo apt-get install php7.x-dev使用sudo aptitude install php7.x-dev

安装能力

sudo apt-get update
sudo apt-get install aptitude

然后运行sudo apt-install php7.x-dev,然后如果提示询问您是否要将以下软件包保留为当前版本:

选择NO这将自动降级或升级版本以便安装php7.x-dev

下一步安装redis:

sudo pecl install --force redis

注意:–force 标志确保添加扩展,而不考虑任何可能阻止安装的缓存设置。

然后你应该添加"extension=redis.so"php.ini。在我的情况下php.ini位于/etc/php/7.3/apache2/php.ini

并通过运行以下命令重新启动 apache2:

sudo service apache2 restart

如果你还没有安装php-fpm运行这个命令。

sudo apt install php7.3-fpm

注意:您需要重新启动php artisan serve. 这是因为即使您成功安装了包(redis,php-dev),laravel 也不会识别 PHP Redis,所以请记住重新启动 php artisan 服务。

于 2020-10-30T14:29:46.617 回答
1

如果您使用的是 heroku,请将其添加到您的要求中:

"ext-redis": "*",
于 2020-07-27T15:34:13.633 回答
0

以防有人偶然发现这一点。我通过安装php-redis在基于 Debian 的 Linux 发行版(基本操作系统)上简单地解决了这个问题。

于 2020-05-07T18:00:58.437 回答
0

我从升级Laravel 5.2Laravel 8

laravel 5.2设置是

'redis' => [

    'cluster' => false,

    'default' => [
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 0,
    ],

],

Laravel 8现在可以正常工作的设置

'redis' => [
        
    'client' => env('REDIS_CLIENT', 'predis'),

    'default' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_DB', 0),
    ],
],
于 2021-12-20T09:55:38.567 回答
-1

如果你使用 Laravel 更新版本 ~8 那么:

您必须更改 2 个文件:

文件 1:在 /bootstrap/cache/config.php 中将 'phpredis' 替换为 'predis'

'redis' => 
    array (
        'client' => 'predis', //you might have 'phpredis'

文件 2:在 /config/database.php 中将 'phpredis' 替换为 'predis'

    'redis' => [
    'client' => env('REDIS_CLIENT', 'predis'),

我的问题就这样解决了

于 2020-11-08T22:52:29.030 回答