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);
        }
    }
相关推荐
万粉变现经纪人6 小时前
如何解决 pip install pyodbc 报错 缺少 ‘cl.exe’ 或 ‘sql.h’(ODBC 头文件)问题
数据库·python·sql·网络协议·bug·ssl·pip
cat2bug1 天前
介绍一下如何在Cat2Bug-Platform中通过OpenAI来创建测试用例
功能测试·测试工具·ai·测试用例·bug·openai
Lz__Heng1 天前
ESXI 6.7.0 update 2(VMware ESXi, 6.7.0, 13006603)监控采集数据已知BUG
bug·vmware
自学也学好编程1 天前
【BUG】Claude Code跳过强制登录解决方法
bug
cat2bug2 天前
介绍一下Cat2Bug-App如何连接自己的Bug平台
bug
秋天枫叶352 天前
【k8s集群Docker + cri-dockerd】服务器重启或关机后 apiserver/controller/scheduler 无法自动恢复
linux·运维·服务器·容器·kubernetes·bug
小趴菜不能喝3 天前
若依Plus 的XSSFilter 的bug
bug
朝新_4 天前
【无标题】软件测试bug篇
bug
e***98575 天前
Bug侦破大会:破解技术悬案的终极策略
bug
缘友一世5 天前
精粤X99-TI D4 PLUS大板使用多显卡BIOS设置
bug·gpu·硬件·主板·x99