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

Viewed 7490

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 :)

3 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');

  • Just remove or comment out extension=php_redis.dll from your php.ini
  • Laravel and server Redis conflicts with name "Redis"
  • This will work

In Laravel database config you can define a client for your Redis handler. As you have installed predis, your Redis database configuration should look like this

'redis' => [

           'client' => 'predis',

           'cluster' => false,

           'default' => [
                  'host' => env('REDIS_HOST', 'localhost'),
                  'password' => env('REDIS_PASSWORD', null),
                  'port' => env('REDIS_PORT', 6379),
                  'database' => 0,
           ],

PhpRedis extension and Laravel alias for Redis Facades are same which is creating the issue. In case you want to use the PhpRedis extension you need to change the alias keyword defined in app.php and client in the database config.

Related