类“Redis”未找到laravel 8,正在使用phpredis

6pp0gazn  于 2022-12-30  发布在  Redis
关注(0)|答案(1)|浏览(369)

我正在使用laravel 8,它是抛出错误,当我试图运行:
第一个月
在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,
zxlwwiss

zxlwwiss1#

好的,我发现了这个问题,有一个更新被推到了ubuntu,这个更新看起来像是默认的php被更新到了php8.0,以前是7.4。

sudo apt-get install php8.0-redis

它看起来像是丢失了php8.0的redis扩展

相关问题