Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-static method Redis::get() cannot be called statically in laravel 5.4?

i am working on Redis to store data Everything is working fine in my local system. i have successfully installed redis also in laravel with this command composer require predis/predis also and Redis setup of window also installed. Now when i store data in Redis like this:-

Redis::set('first',"My first Test"); // put data in Redis key
echo Redis ::get('first'); // get data

Above code is working fine in my local system. when i try to use this code in live server it is showing the below error:- enter image description here Please help me to resolve this issue. We are using amazon-ec2 server Thanks in advance :)

like image 705
kunal Avatar asked Sep 14 '17 07:09

kunal


2 Answers

I had the same issue. But I believe its related to php 7 rather than Larevel 5.4 because I'm using Laravel 5.1 and I still have the problem.

I came across 2 solutions

  1. Use use Illuminate\Support\Facades\Redis; instead of use Redis; if you want to call the Redis methods statically.
  2. Change to dynamic calling

$redis = new Redis(); $redis->set('boo','Have beer and relax!') $redis->get('boo');

like image 144
Santhosh Avatar answered Oct 10 '22 04:10

Santhosh


  • Just remove or comment out extension=php_redis.dll from your php.ini
  • Laravel and server Redis conflicts with name "Redis"
  • This will work
like image 35
Ahsan Horani Avatar answered Oct 10 '22 04:10

Ahsan Horani