Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

harishkumar's avatar

Laravel 5.6 getting error “Class 'Predis\Client' not found”

I do not want to use predis in laravel project. So, I have installed phpredis in my ubuntu system, php 7.2 and apache.

I have installed redis using following commands:

sudo apt-get install redis-server
sudo apt-get install php-redis

Here is my code where I have used redis: TrendingAbstract.php

<?php

namespace App\Trends;

use App\Trends\Contracts\Trending;
use Illuminate\Support\Facades\Redis;

abstract class TrendingAbstract implements Trending
{
    /**
    * Fetch all trending resource
    *
    * @param  integer $limit
    * @return array
    */
    public function get($limit = 1)
    {
        return array_map('json_decode', Redis::zrevrange($this->cacheKey(), 0, $limit - 1));
    }

    /**
     * Reset all trending resource.
     */
    public function reset()
    {
        Redis::del($this->cacheKey());
    }
}

TrendingArticles.php

<?php

namespace App\Trends;

use App\Models\Article;
use Illuminate\Support\Facades\Redis;

class TrendingArticles extends TrendingAbstract
{
    /**
     * Get the cache key name.
     *
     * @return string
     */
    public function cacheKey()
    {
        return 'trending_article';    
    }

    /**
     * Push a new resource to the trending list.
     *
     * @param App\Models\Article $article
     */
    public function push(Article $article)
    {
        Redis::zincrby($this->cacheKey(), 1, json_encode([
            'title' => $article->title,
            'path' => $article->path
        ]));
    }
}

I did not understand what is the issue here. Same code is working fine with my another project in laravel 5.5. But not working in Laravel 5.6.

Does I am missing any configuration for phpredis? Please guide.

0 likes
2 replies
rin4ik's avatar

Go to your project directory and install this dependency

composer require predis/predis
2 likes
Cronix's avatar

The docs do mention that. https://laravel.com/docs/5.6/session#driver-prerequisites

Before using Redis sessions with Laravel, you will need to install the predis/predis package (~1.0) via Composer. You may configure your Redis connections in the database configuration file. In the session configuration file, the connection option may be used to specify which Redis connection is used by the session.

https://laravel.com/docs/5.6/redis#introduction

Before using Redis with Laravel, you will need to install the predis/predis package via Composer: composer require predis/predis

Please or to participate in this conversation.