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

后端 未结 4 1025
情歌与酒
情歌与酒 2021-02-08 11:37

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

4条回答
  •  独厮守ぢ
    2021-02-08 12:06

    The problem isn't with your redis server setup -- there's something mis-configured or changed in your system.

    The error you're seeing

    Call to undefined method Redis::connection()
    

    Is PHP telling you it can't find a method named connection on the class Redis. It's a PHP error, and PHP never gets around to trying to talk to the redis server.

    Normally, in a Laravel 4.2 system, there is no class named Redis. Instead, an alias is setup in app/config/app.php

    #File: app/config/app.php
    'Redis'           => 'Illuminate\Support\Facades\Redis',
    

    which turns Redis into a facade. This is what enables you to make calls like Redis::connection.

    So, there's something wrong with your system. Either you

    1. Have a custom class named Redis somewhere that's loaded before the aliases are setup

    2. Have Redis aliased to something other than a the Illuminate\Support\Facades\Redis facade class

    3. You Redis facade class has been modified to return a service identifier other than redis

    4. You've rebound the redis service as some other class

    5. Per the comments below, you have the Redis PHP extension installed and the global extension class "wins"

    To find out where PHP thinks the Redis class is, try

    $r = new ReflectionClass('Redis');
    var_dump($r->getClassFile());
    

    To see if #4 is the problem, try calling the service directly

    $app = app();
    $app['redis']->connection();
    

    Good luck!

提交回复
热议问题