36

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,
1
  • 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. Commented Feb 1, 2023 at 12:55

7 Answers 7

66

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
Sign up to request clarification or add additional context in comments.

3 Comments

in the database.php file, replace the following line: 'client' => env('REDIS_CLIENT', 'phpredis') to: 'client' => env('REDIS_CLIENT', 'predis')
For Windows users this was the best answer ever! Just 2 steps and everything worked as it should! Thanks @kovarov
this is not right solution for someone wants phpredis not predis.
22

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

4 Comments

Unable to locate package php8.1-redis
@Pathros me too having same issue unable to locate
sudo apt-get install php8.1-redis seems to work for me Ubuntu 20.x LTS
Just look the package name with apt search php | grep redis. then install the package
4

I had the same issue, and I was able to resolve it by installing Redis and Redis Server. Follow these steps:

Install Redis for PHP:

sudo apt-get install php8.3-redis

Check your PHP version using php -v and substitute 8.3 with your actual PHP version.

Install Redis Server:

sudo apt install redis-server

Comments

1

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

composer require predis/predis

in your .env file add this lines

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

1 Comment

npm install really? composer install predis/predis would be fine
1

Many people suggest to use predis but it is less performant and not the solution if someone need to use phpredis (which is default).

if you have installed phpredis correctly using pecl and it only throws error in artisan command, it might be redis is loaded in FPM(if you use php fpm) but not in CLI.

you can echo "extension=redis.so" >> /etc/php/8.2/cli/php.ini

**should change 8.2 to your php version.

Comments

0

add this to app.php file

  'aliases' => Facade::defaultAliases()->merge([
        'Redis' => Illuminate\Support\Facades\Redis::class,
    ])->toArray(),

Comments

0

for such issues, please delete the ./bootstrap/cache/*.php files and run command again.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.