Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 : Call to undefined method Redis::connection()

I'm going crazy about this error. I've got a vagrant VM with Debian 7, generated with Puphpet, installation was fine.

1. Redis is installed and working

redis-server is running :

redis-server running

I can use the server on 127.0.0.1:6379 :

enter image description here

2. php5-redis is installed

php5-redis is actually installed :

enter image description here

3. Laravel Redis config is set

Here is my redis config file in app/local/database.php :

'redis' => [

    'cluster' => false,

    'default' => [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 0,
    ],
],

4. The call to Redis is simple :

// Get redis
$redis = Redis::connection();

5. I tried a lot of things

sudo service nginx reload
sudo service redis-server force-reload
composer dumpautoload

But nothing solved the error.


I'm still having :

ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Redis::connection()' in /var/www/fd/app/menus/admin.menu.php:16

(line 16 is where I do the connection $redis = Redis::connection();)

Where am I wrong ?

Btw, I hate mondays >.>

like image 832
grena Avatar asked Sep 22 '14 13:09

grena


1 Answers

I came across this after encountering this issue and wanted to add another answer in case it helps someone else.

In my case there was an alias collision because my php configuration has the PHP-Redis module/extension enabled -- both the PHP module and Laravel seem to have a conflicting object named Redis. I was able to resolve this simply by using the entire namespaced identifier:

//$r = Redis::connection() 
$r = Illuminate\Support\Facades\Redis::connection();
like image 122
Neil Neyman Avatar answered Sep 21 '22 20:09

Neil Neyman