8
votes

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
Had you also tried this command in server?: composer require predis/predisHiren Gohel
i have uploaded vendor folder and composer.jsonkunal
I think we never upload vendor folder in server, just update composer and that install all packages using composer update!Hiren Gohel
but every time when i iintsalled package in my local system like maatwebsite excel,.. etc i have uploaded vendor folder and composer .json then that was running finekunal
Yeah its fine, but actual thing is we never uploads the vendor folder in server/git. We always ignore in .gitignore file. Just update composer.json file and composer update in server. So, that installed all package files in their vendor folder! And not missing any files!Hiren Gohel

3 Answers

25
votes

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

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

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.