skip to Main Content

I am using laravel 8, and it is throwing error, when ever I tried to run:

php artsian config:clear

On laravel, this is my config value (because I am trying to use phpredis):

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

I could use redis-cli and ping at the moment. Not, just that I could hit the following endpoint successfully.

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

It prints out pong successfully.

but I am receiving class Redis not found. Whenever I tried to run, php artisan config:clear

Full error looks like this:

  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
      IlluminateSupportFacadesFacade::__callStatic()

  12  app/Providers/AppServiceProvider.php:37
      AppModelsSetting::getCachedValue()

and my AppModelsSetting looks like:

<?php

namespace AppModels;

use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateSupportFacadesCache;

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();
    }
}

What, I might be doing wrong here.
#PS: This line on my config/app is commented.

// 'Redis' => IlluminateSupportFacadesRedis::class,

2

Answers


  1. Chosen as BEST ANSWER

    Okay, I found the issue, there was updated pushed to ubuntu, and with this update looks like default php was updated to php8.0, previously it was 7.4. So, running following command fix the issue.

    sudo apt-get install php8.0-redis
    

    It looks like it was missing redis extension for php 8.0


  2. you must specify "REDIS CLIENT" in your .env file after installation

    composer require predis/predis
    

    in the .env file add these lines

    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379
    REDIS_CLIENT=predis
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search