Go to your project directory and install this dependency
composer require predis/predis
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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.
Please or to participate in this conversation.