Laravel 4:调用未定义的方法Redis :: connection() [英] Laravel 4 : Call to undefined method Redis::connection()
问题描述
我为这个错误而疯狂. 我有一个带有Debian 7的无聊的VM,是用Puphpet生成的,安装很好.
I'm going crazy about this error. I've got a vagrant VM with Debian 7, generated with Puphpet, installation was fine.
redis-server
正在运行:
我可以在127.0.0.1:6379
上使用服务器:
I can use the server on 127.0.0.1:6379
:
php5-redis
实际上已安装:
这是我在app/local/database.php
中的redis配置文件:
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. Redis的调用很简单:
// Get redis
$redis = Redis::connection();
5.我尝试了很多事情
sudo service nginx reload
sudo service redis-server force-reload
composer dumpautoload
但是没有任何方法可以解决错误.
But nothing solved the error.
我还有:
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
(第16行是我进行连接$redis = Redis::connection();
的位置)
(line 16 is where I do the connection $redis = Redis::connection();
)
我在哪里错了?
顺便说一句,我讨厌星期一>.>
Btw, I hate mondays >.>
推荐答案
遇到此问题后,我遇到了这个问题,并想添加另一个答案,以防其他人得到帮助.
I came across this after encountering this issue and wanted to add another answer in case it helps someone else.
在我的情况下,发生别名冲突是因为我的php配置启用了PHP-Redis模块/扩展-PHP模块和Laravel似乎都有一个名为Redis的冲突对象.我可以通过使用整个命名空间标识符来简单地解决此问题:
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();
这篇关于Laravel 4:调用未定义的方法Redis :: connection()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!