【问题标题】:Class "Redis" Not Found laravel 8, using phpredis未找到类“Redis”laravel 8,使用 phpredis
【发布时间】:2022-01-01 15:33:37
【问题描述】:

我使用的是 laravel 8,当我尝试运行时它会抛出错误:

php artsian config:clear

在 laravel 上,这是我的配置值(因为我正在尝试使用 phpredis):

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

我现在可以使用 redis-cli 和 ping。不,只是我可以成功到达以下端点。

    public function testRedis()
    {
        Redis::set('ping','pong');
        $ping = Redis::get('ping');
        dd($ping);
    }

成功打印出pong

但我正在接收课程 Redis 未找到。每当我尝试运行时,php artisan config:clear

完整错误如下所示:

  Class "Redis" not found

  at vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:75
     71▕      * @throws \LogicException
     72▕      */
     73▕     protected function createClient(array $config)
     74▕     {
  ➜  75▕         return tap(new Redis, function ($client) use ($config) {
     76▕             if ($client instanceof RedisFacade) {
     77▕                 throw new LogicException(
     78▕                     extension_loaded('redis')
     79▕                         ? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'

      +10 vendor frames 
  11  app/Models/Setting.php:34
      Illuminate\Support\Facades\Facade::__callStatic()

  12  app/Providers/AppServiceProvider.php:37
      App\Models\Setting::getCachedValue()

我的App\Models\Setting 看起来像:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

class Setting extends Model
{
    use HasFactory;
    
    protected $table = 'settings';
    protected $guarded = ['id'];
    protected $dates = ['created_at','updated_at'];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'created_at' => 'datetime:Y-m-d', // Change your format
        'updated_at' => 'datetime:Y-m-d',
    ];

    const STRIPE_ENVIRONMENT = ['test', 'live'];

    public static function getCachedValue(){
        return Cache::rememberForever('settings', function () {
            return Setting::pluck('key_value', 'key_name');
        });
    }

    public static function updateCachedSettingsData(){
        Cache::forget('settings');
        self::getCachedValue();
    }
}

什么,我可能在这里做错了。 #PS:我的config/app 上的这一行已被评论。

// 'Redis' => Illuminate\Support\Facades\Redis::class,

【问题讨论】:

    标签: laravel redis phpredis


    【解决方案1】:

    好的,我找到了问题,有更新推送到 ubuntu,这次更新看起来默认 php 更新到 php8.0,之前是 7.4。因此,运行以下命令可以解决问题。

    sudo apt-get install php8.0-redis
    

    看起来它缺少 php 8.0 的 redis 扩展

    【讨论】:

      猜你喜欢
      • 2014-09-11
      • 1970-01-01
      • 2021-03-13
      • 2021-06-18
      • 1970-01-01
      • 2021-01-08
      • 2021-08-06
      • 1970-01-01
      • 2021-03-11
      相关资源
      最近更新 更多