18

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
      Illuminate\Support\Facades\Facade::__callStatic()

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

and my App\Models\Setting looks like:

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

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

// 'Redis' => Illuminate\Support\Facades\Redis::class,
Aayush Dahal
  • 856
  • 1
  • 17
  • 51
  • It looks like the PHP Redis extension is not installed, You can check if the Redis PHP extension is installed & enable. Redis is installed, configured & running. – Md. A. Apu Feb 01 '23 at 12:55

2 Answers2

26

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
kovarov
  • 465
  • 5
  • 11
13

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

Aayush Dahal
  • 856
  • 1
  • 17
  • 51