colinmollenhour/credis 1.17 bug

复制代码
Call to a member function getMode() on null

vendor\colinmollenhour\credis\Client.php(783): Credis_Client->assertNotPipelineOrMulti('Credis_Client::...')

错误代码

php 复制代码
#Credis_Client vendor\colinmollenhour\credis\Client.php

   /**
     * @param ?int $Iterator
     * @param string $pattern
     * @param int $count
     * @return bool|array
     * @throws CredisException
     */
    public function scan(&$Iterator, $pattern = null, $count = null) {
        $this->assertNotPipelineOrMulti(__METHOD__);
        return $this->__call('scan', array(&$Iterator, $pattern, $count));
    }

    /**
     * @param string $caller
     * @return void
     * @throws CredisException
     */
    protected function assertNotPipelineOrMulti($caller) {
        if ($this->standalone && ($this->isMulti || $this->usePipeline) ||
            // phpredis triggers a php fatal error, so do the check before
            !$this->standalone && ($this->redis->getMode() === Redis::MULTI || $this->redis->getMode() === Redis::PIPELINE)) {
            throw new CredisException('multi()/pipeline() mode can not be used with ' . $caller);
        }
    }

报错是这个代码 "this-\>redis-\>getMode()",其中this->redis为空。

调用代码

php 复制代码
$client = new Credis_Client();
$r = $client->select(15);
$data = $client->scan($client, "keywords:*", 1);
var_dump($data);

此时代码正常

php 复制代码
$host = '127.0.0.1';
$port = 6379;
$timeout = null;
$persistent = '';
$db = 15;
$client = new Credis_Client($host,$port,$timeout ,$persistent,$db);

$data = $client->scan($client, "keywords:*", 1);
var_dump($data);
var_dump(123);

会报上面的错误,就是Credis_Client构造里$this->redis没初始化。

使用懒加载,都是调用方法之后实现连接,实例化$this->redis。

可以按照正常顺序调用,也可以改代码。

修改后代码

php 复制代码
protected function assertNotPipelineOrMulti($caller) {
        if (empty($this->redis)) {
            $this->connect();
        }
        if ($this->standalone && ($this->isMulti || $this->usePipeline) ||
            // phpredis triggers a php fatal error, so do the check before
            !$this->standalone && ($this->redis->getMode() === Redis::MULTI || $this->redis->getMode() === Redis::PIPELINE)) {
            throw new CredisException('multi()/pipeline() mode can not be used with ' . $caller);
        }
    }
相关推荐
这个软件需要设计一下1 天前
ninedata安装磁盘不足问题解决
运维·bug
热爱生活的五柒1 天前
cc-switch安装方法、介绍及遇到的bug
bug·cc-switch
Greenland_121 天前
Android 混淆与混淆后bug日志问题定位
android·bug
应用市场1 天前
踩坑记录:有符号整数位运算的那些隐蔽Bug——符号扩展、算术右移与补码
java·开发语言·bug
一灰灰blog2 天前
Jar包会自己消失?Excel会“记忆“数据?我遇到了两个灵异bug
java·spring boot·bug·excel
王家视频教程图书馆3 天前
修复服务端500相应,修复客户端上传文件.tmp 服务端接受不到文件bug
bug
qq_401700413 天前
Qt开发过程中遇到哪些经典的bug
qt·bug
0白露5 天前
关闭搜狗输入法右下角广告,可以适用于大多数应用系统通知的广告
windows·bug
一只自律的鸡6 天前
【Linux驱动】bug处理 ens33找不到IP
linux·运维·bug
Lichenpar7 天前
Springboot采用FastJson2作为MessageConverter时,配置的全局日期类型序列化转换BUG
java·开发语言·bug