laravel redis 扩展冲突的问题分析:Fatal error: Non-static method Redis::keys() cannot be called statically
来源:互联网 发布:c语言中大小写字母转换 编辑:程序博客网 时间:2024/06/05 12:44
laravel中,出现 'Fatal error: Non-static method Redis::keys() cannot be called statically' 的问题分析:1.这里不得不吐槽下。按理说,这个问题,是一个很容易发生的问题!网上各种搜索,很难明白是什么原因。最多是一个 'redis命名空间冲突',让我们不要引用 'Redis',而是1.将 'config/app.php' 中的 Redis别名,修改为 'Redisxx',换一个不会冲突的2.将项目中的 'use Redis;',改为 'Illuminate\Support\Facades\Redis' 反正就是指定全路径这确实是正确的,但我之前的环境可以使用,现在的环境不可用,我不能将之前的代码中,所有的都进行替换啊,有点痛苦!2.找了很多文章,外加昨天正好总结了 "PHP的扩展安装" - http://blog.csdn.net/beyond__devil/article/details/65934701pecl,pear,phpize,php-config 等,都了解了点(原谅我,现在居然才开始看这个,还干了3年PHP了。。。) 大概了解产生这个问题的原因了,分析如下:1>我现在默认的集成环境中,系统已经安装了 redis,并且,系统的PHP,也已经安装了 'PhpRedis' 的 PECL扩展,也就是 redis.so // 它已经占据了 'Redis' 命名空间2>laravel框架,文档中,也指出了,我们使用redis,需要安装 composer require predis/predis // 它也使用的是 'Redis' 命名空间 2者都是Redis扩展,使用了 Redis 命名空间,所以导致冲突!3.了解了问题所在,我们就可进行修复:1>就是上面所说的,修改通过 composer 安装的 predis 的命名空间。又分2种:1)修改 'app/config.php',将 'Redis',改为 'RedisDB'。然后,每次引用Redis Facade时,使用 RedisDB 来替换2)在每个使用 use Redis; 的文件中,我们改为 use Illuminate\Support\Facades\Redis;2>我的服务器项目,只基于laravel,我在php配置文件中,注释掉 ';extension redis.so',不使用 pecl 安装的redis扩展,直接使用 composer 安装的redis扩展(也算推荐吧,以后我们得熟悉 composer 来搭建php应用)参考文章:https://laravel.com/docs/5.4/redis // laravel "英文" 官方文档(中文翻译的之前的版本,有的信息没有)1>官方文档中,有这么一句话:Alternatively, you may install the PhpRedis PHP extension via PECL. The extension is more complex to install but may yield better performance for applications that make heavy use of Redis.意思是:你也可以通过PECL安装 PhpRedis 扩展。在大量使用 redis 的PHP应用中,使用 PECL 安装的redis.so扩展,会产生更高的性能(通过我上面的教程,应该了解到 pecl 扩展,是使用 c、c++等开发的),但是就是安装稍微复杂点2>接着官方的redis文档,直接红色的警告!!!!/*If you have the PhpRedis PHP extension installed via PECL, you will need to rename the Redis alias in your config/app.php configuration file. */如果,使用了 pecl 安装的 redis.so,我们在 'config/app.php' 中,就需要重命名 'Redis' 别名。3>如果,我们就想使用 pecl 安装的 'redis.so' (扩展名为:PhpRedis),我们需要配置:config/database.php'redis' => ['client' => 'phpredis',],除了默认的host ,port, database和password配置,PhpRedis还支持 persistent, prefix, read_timeout, timeout。可在 'config/database.php' 中配置总结:官方文档,就已经解释了很清楚了,我居然不知道。。。还是我这个问题,太低级了。。。
1 0
- laravel redis 扩展冲突的问题分析:Fatal error: Non-static method Redis::keys() cannot be called statically
- Non-static method Redis::hSet() cannot be called statically
- ecshop二次开发:Non-static method cls_image::gd_version() should not be called statically in的解决
- php错误:non-static method xxx()should not be called statically
- Strict standards: Non-static method cls_image::gd_version() should not be called statically in
- Non-static method cls_image::gd_version() should not be called statically in D:\X\www\ecshop\install
- ECMall报Strict Standards: Non-static method Conf::get() should not be called statically解决
- 安装ECShop报 Non-static method cls_image::gd_version() should not be called statically 解决方案
- 安装ecmall报错Strict Standards: Non-static method ECMall::startup() should not be called statically in D
- error: interface type cannot be statically allocated 学习object-c的时候遇到的小问题
- Non-static method cannot be referenced from a static context
- ECshop安装问题一解决:Strict Standards: Non-static method cls_image::gd_version() should not be called stati
- laravel引入laterll的alipay支付问题:Non-static method Symfony\Component\HttpFoundation\Request::getQueryStri
- Redis keys 性能问题
- error: Semantic Issue: Interface type cannot be statically allocated
- 自学JAVA之Cannot make a static reference to the non-static method分析
- Data is Null. This method or property cannot be called on Null values.错误分析
- MOSS爬网问题Error from SharePoint site: Data is Null. This method or property cannot be called on Null values
- 最小生成树
- JavaScript新创建对象的一些属性和方法
- 朴素贝叶斯分类算法
- 希腊字母
- JAVA设计模式之工厂模式(简单工厂模式+工厂方法模式)
- laravel redis 扩展冲突的问题分析:Fatal error: Non-static method Redis::keys() cannot be called statically
- spring boot+ Intellj idea devtool 设置热部署
- 字符串匹配的KMP算法
- 实现textarea限制输入字数
- 是时候学习RxJava了
- 【算法】字符串分类
- 0002_Add Two Numbers
- Map集合的四种遍历方式
- Floyd多源最短路径算法